This repository was archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgame_runtime_error_handler.js
221 lines (171 loc) · 6.38 KB
/
game_runtime_error_handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
const rw = require("./reader_writer.js");
//Exact error: "Failed to create temp dir 'C:\Users\MistZ\AppData\Local\Temp/dom5_94132'"
const failedToCreateTmpDirErrRegexp = new RegExp("Failed\\s*to\\s*\\create\\s*temp\\s*dir", "i");
//Exact error: "send: Broken pipe"
const brokenPipeErrRegexp = new RegExp("broken\\s*pipe", "i");
//Exact error: "bind: Address already in use"
const addressInUseErrRegexp = new RegExp("address\\s*already\\s*in\\s*use", "i");
//Exact error: "Terminated"
const terminatedErrRegexp = new RegExp("terminated", "i");
//Exact error: "Map specified by --mapfile was not found"
const mapNotFoundErrRegexp = new RegExp("Map\\s*specified\\s*by\\s*--mapfile", "i");
//Exact error: "myloadmalloc: can't open [path].tga/rgb/png"
const mapImgNotFoundErrRegexp = new RegExp("can\\'t\\s*open\\s*.+.(tga)|(.rgb)|(.rgb)|(.png)$", "i");
//Exact error: "bc: king has throne in capital (p43 c385 h160 vp2) [new game created]"
const throneInCapitalErrRegexp = new RegExp("king\\s*has\\s*throne\\s*in\\s*capital", "i");
//Exact error: "bad ai player"
const badAiPlayerErrRegexp = new RegExp("bad\\s*ai\\s*player", "i");
//Exact error: "/home/steam/Steam/Dominions5/dom5.sh: line 20: 26467 Aborted (core dumped) "$BIN" "$@""
const coreDumpedErrRegexp = new RegExp("\\(core\\s*dumped\\)", "i");
/* Exact error: "Dominions version is too old *
* Get an update at www.illwinter.com *
* myversionX fileversionY nationZ" */
const versionTooOldErrRegexp = new RegExp("version\\s*is\\s*too\\s*old", "i");
//Exact error: "Något gick fel!". Should come last in handling as some more
//errors will also contain this bit into them
const nagotGickFelErrRegexp = new RegExp("gick\\s*fel", "i");
//Exact error: "h_mkitms"
//johan has stated that this is an error about forging a bad magic item that shouldn't happen
const itemForgingErrRegexp = new RegExp("h_mkitms", "i");
//Exact error: "Failed to create /[statuspage name]"
const fileCreationErrRegexp = new RegExp("Failed\\s*to\\s*create", "i");
module.exports = function(game, errStr)
{
if (typeof errStr !== "string")
{
return `Could not identify error.`;
}
if (failedToCreateTmpDirErrRegexp.test(errStr) === true)
{
handleFailedToCreateTmpDir(game, errStr);
}
else if (brokenPipeErrRegexp.test(errStr) === true)
{
handleBrokenPipe(game, errStr);
}
else if (addressInUseErrRegexp.test(errStr) === true)
{
handleAddressInUse(game, errStr);
}
else if (terminatedErrRegexp.test(errStr) === true)
{
handleTerminated(game, errStr);
}
else if (mapNotFoundErrRegexp.test(errStr) === true)
{
handleMapNotFound(game, errStr);
}
else if (mapImgNotFoundErrRegexp.test(errStr) === true)
{
handleMapImgNotFound(game, errStr);
}
else if (throneInCapitalErrRegexp.test(errStr) === true)
{
handleThroneInCapital(game, errStr);
}
else if (badAiPlayerErrRegexp.test(errStr) === true)
{
handleBadAiPlayer(game, errStr);
}
else if (coreDumpedErrRegexp.test(errStr) === true)
{
handleCoreDumped(game, errStr);
}
else if (versionTooOldErrRegexp.test(errStr) === true)
{
handleVersionTooOld(game, errStr);
}
else if (itemForgingErrRegexp.test(errStr) === true)
{
handleItemForgingErr(game, errStr);
}
else if (fileCreationErrRegexp.test(errStr) === true)
{
handleFileCreationErr(game, errStr);
}
else if (nagotGickFelErrRegexp.test(errStr) === true)
{
handleNagotGickFel(game, errStr);
}
else
{
rw.log("error", `The game ${game.name} reported an unknown error: ${errStr}`);
sendWarning(game, `The game ${game.name} reported the error: ${errStr}`);
}
}
function handleFailedToCreateTmpDir(game, errStr)
{
sendWarning(game, `Dominions reported an error: the game instance could not be started because it failed to create a temp dir. Try killing it and launching it again.`);
}
function handleBrokenPipe(game, errStr)
{
}
function handleAddressInUse(game, errStr)
{
sendWarning(game, `The port used by this game is already in use. Most likely the game failed to shut down properly, so killing it and relaunching it should work.`);
}
function handleTerminated(game, errStr)
{
}
function handleNagotGickFel(game, errStr)
{
sendWarning(game, `Dominions crashed due to an error.`);
}
function handleMapNotFound(game, errStr)
{
//if game started less than 5 minutes ago, set wasStarted to false as it could not do so properly
if (Date.now() - game.startedAt <= 300000)
{
game.wasStarted = false;
}
//this error string is pretty explicit and informative so send it as is
sendWarning(game, errStr);
}
function handleMapImgNotFound(game, errStr)
{
//if game started less than 5 minutes ago, set wasStarted to false as it could not do so properly
if (Date.now() - game.startedAt <= 300000)
{
game.wasStarted = false;
}
sendWarning(game, `Dominions reported an error: One or more of the image files of the selected map could not be found. Make sure they've been uploaded and that the .map file points to the proper names.`);
}
function handleThroneInCapital(game, errStr)
{
//if game started less than 5 minutes ago, set wasStarted to false as it could not do so properly
if (Date.now() - game.startedAt <= 300000)
{
game.wasStarted = false;
}
sendWarning(game, `Dominions reported an error: A throne was probably forced to start on a player's capital. Check the pre-set starts and thrones in the .map file (original error is: bc: king has throne in capital (p43 c385 h160 vp2) [new game created])`);
}
function handleBadAiPlayer(game, errStr)
{
sendWarning(game, `Dominions reported an error: one of the AI players has an invalid nation number.`);
}
function handleCoreDumped(game, errStr)
{
//don't send error here as this comes coupled with other more explicit errors
}
function handleVersionTooOld(game, errStr)
{
sendWarning(game, `The game has crashed because a new Dominions version is available. Please be patient while the admins update the servers :)`);
}
function handleItemForgingErr(game, errStr)
{
sendWarning(game, `The game has crashed on turn generation due to an error caused by forging a bad item. This should theoretically not happen.`);
}
function handleFileCreationErr(game, errStr)
{
}
function sendWarning(game, warning)
{
if (game.channel != null)
{
game.channel.send(warning);
}
else if (game.organizer != null)
{
game.organizer.send(warning);
}
}