@arken/seer-protocol 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintrc +123 -0
- package/.prettierrc +12 -0
- package/.rush/temp/shrinkwrap-deps.json +420 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/package.json +25 -0
- package/src/index.ts +22 -0
- package/src/modules/evolution/evolution.models.ts +3 -0
- package/src/modules/evolution/evolution.router.ts +3738 -0
- package/src/modules/evolution/evolution.schema.ts +1 -0
- package/src/modules/evolution/evolution.service.ts +2000 -0
- package/src/modules/evolution/evolution.types.ts +20 -0
- package/src/modules/evolution/index.ts +5 -0
- package/src/modules/infinite/index.ts +5 -0
- package/src/modules/infinite/infinite.models.ts +3 -0
- package/src/modules/infinite/infinite.router.ts +3648 -0
- package/src/modules/infinite/infinite.schema.ts +1 -0
- package/src/modules/infinite/infinite.service.ts +40 -0
- package/src/modules/infinite/infinite.types.ts +20 -0
- package/src/modules/isles/index.ts +5 -0
- package/src/modules/isles/isles.models.ts +3 -0
- package/src/modules/isles/isles.router.ts +3648 -0
- package/src/modules/isles/isles.schema.ts +1 -0
- package/src/modules/isles/isles.service.ts +40 -0
- package/src/modules/isles/isles.types.ts +20 -0
- package/src/modules/oasis/index.ts +5 -0
- package/src/modules/oasis/oasis.models.ts +3 -0
- package/src/modules/oasis/oasis.router.ts +68 -0
- package/src/modules/oasis/oasis.schema.ts +1 -0
- package/src/modules/oasis/oasis.service.ts +38 -0
- package/src/modules/oasis/oasis.types.ts +20 -0
- package/src/modules/trek/index.ts +5 -0
- package/src/modules/trek/trek.models.ts +1 -0
- package/src/modules/trek/trek.router.ts +78 -0
- package/src/modules/trek/trek.schema.ts +1 -0
- package/src/modules/trek/trek.service.ts +1031 -0
- package/src/modules/trek/trek.types.ts +1 -0
- package/src/router.ts +130 -0
- package/src/types.ts +106 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,3648 @@
|
|
|
1
|
+
import { z as zod } from 'zod';
|
|
2
|
+
import { initTRPC } from '@trpc/server';
|
|
3
|
+
import { customErrorFormatter, hasRole } from '@arken/node/util/rpc';
|
|
4
|
+
import * as Arken from '@arken/node';
|
|
5
|
+
import { Query, getQueryInput, inferRouterOutputs, inferRouterInputs } from '@arken/node/schema';
|
|
6
|
+
import { RouterContext } from '../../types';
|
|
7
|
+
|
|
8
|
+
export const z = zod;
|
|
9
|
+
export const t = initTRPC.context<RouterContext>().create();
|
|
10
|
+
export const router = t.router;
|
|
11
|
+
export const procedure = t.procedure;
|
|
12
|
+
|
|
13
|
+
export const createRouter = () =>
|
|
14
|
+
router({
|
|
15
|
+
saveRound: procedure
|
|
16
|
+
.use(hasRole('guest', t))
|
|
17
|
+
.use(customErrorFormatter(t))
|
|
18
|
+
.input(
|
|
19
|
+
z.object({
|
|
20
|
+
shardId: z.string(),
|
|
21
|
+
roundId: z.number(),
|
|
22
|
+
round: z.any(),
|
|
23
|
+
rewardWinnerAmount: z.number(),
|
|
24
|
+
lastClients: z.any(),
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
// .output(Arken.Profile.Schemas.Profile)
|
|
28
|
+
.query(({ input, ctx }) => (ctx.app.service.Evolution.saveRound as any)(input, ctx)),
|
|
29
|
+
|
|
30
|
+
interact: t.procedure
|
|
31
|
+
.use(hasRole('guest', t))
|
|
32
|
+
.use(customErrorFormatter(t))
|
|
33
|
+
.input(
|
|
34
|
+
z.object({
|
|
35
|
+
shardId: z.string(),
|
|
36
|
+
roundId: z.number(),
|
|
37
|
+
round: z.any(),
|
|
38
|
+
rewardWinnerAmount: z.number(),
|
|
39
|
+
lastClients: z.any(),
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Evolution.saveRound as any)(input, ctx)),
|
|
43
|
+
|
|
44
|
+
getScene: t.procedure
|
|
45
|
+
.use(hasRole('guest', t))
|
|
46
|
+
.use(customErrorFormatter(t))
|
|
47
|
+
.input(
|
|
48
|
+
z.object({
|
|
49
|
+
data: z.any(),
|
|
50
|
+
signature: z.object({ hash: z.string(), address: z.string() }),
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
|
+
.mutation(({ input, ctx }) => (ctx.app.service.Evolution.saveRound as any)(input, ctx)),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export type Router = ReturnType<typeof createRouter>;
|
|
57
|
+
export type RouterInput = inferRouterInputs<Router>;
|
|
58
|
+
export type RouterOutput = inferRouterOutputs<Router>;
|
|
59
|
+
|
|
60
|
+
// unbanClient: t.procedure
|
|
61
|
+
// .input(z.object({ data: z.object({ target: z.string() }), id: z.string() }))
|
|
62
|
+
// .mutation(({ input, ctx }) => {
|
|
63
|
+
// service.unbanClient(ctx.app, input);
|
|
64
|
+
// }),
|
|
65
|
+
|
|
66
|
+
// mod: t.procedure
|
|
67
|
+
// .input(
|
|
68
|
+
// z.object({
|
|
69
|
+
// data: z.object({
|
|
70
|
+
// body: z.object({ signature: z.object({ address: z.string() }) }),
|
|
71
|
+
// params: z.object({ method: z.string() }),
|
|
72
|
+
// }),
|
|
73
|
+
// })
|
|
74
|
+
// )
|
|
75
|
+
// .mutation(({ input, ctx }) => {
|
|
76
|
+
// service.mod(ctx.app, input);
|
|
77
|
+
// }),
|
|
78
|
+
|
|
79
|
+
// banClient: t.procedure
|
|
80
|
+
// .input(
|
|
81
|
+
// z.object({
|
|
82
|
+
// data: z.object({ target: z.string(), reason: z.string(), until: z.number().optional() }),
|
|
83
|
+
// id: z.string(),
|
|
84
|
+
// })
|
|
85
|
+
// )
|
|
86
|
+
// .mutation(({ input, ctx }) => {
|
|
87
|
+
// service.banClient(ctx.app, input);
|
|
88
|
+
// }),
|
|
89
|
+
|
|
90
|
+
// getCharacter: t.procedure
|
|
91
|
+
// .input(z.object({ data: z.object({ address: z.string() }), id: z.string() }))
|
|
92
|
+
// .mutation(({ input, ctx }) => {
|
|
93
|
+
// service.getCharacter(ctx.app, input);
|
|
94
|
+
// }),
|
|
95
|
+
|
|
96
|
+
// saveRound: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
97
|
+
// service.saveRound(ctx.app, input);
|
|
98
|
+
// }),
|
|
99
|
+
|
|
100
|
+
// Add more procedures as necessary
|
|
101
|
+
|
|
102
|
+
// Add the router type export if necessary
|
|
103
|
+
// export type Router = ReturnType<typeof createRouter>;
|
|
104
|
+
|
|
105
|
+
// class service {
|
|
106
|
+
// private characters: Record<string, any> = {};
|
|
107
|
+
|
|
108
|
+
// async pingRequest(msg: any) {
|
|
109
|
+
// log('PingRequest', msg);
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
// async pongRequest(msg: any) {
|
|
113
|
+
// log('PongRequest', msg);
|
|
114
|
+
// }
|
|
115
|
+
|
|
116
|
+
// async unbanClient(app: Application, req: { data: { target: string }; id: string }) {
|
|
117
|
+
// log('unbanClient', req);
|
|
118
|
+
|
|
119
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
120
|
+
// delete user.isBanned;
|
|
121
|
+
// delete user.bannedReason;
|
|
122
|
+
// await app.db.saveUser(user);
|
|
123
|
+
|
|
124
|
+
// app.db.removeBanList('evolution', req.data.target);
|
|
125
|
+
// app.db.saveBanList();
|
|
126
|
+
|
|
127
|
+
// return { status: 1 };
|
|
128
|
+
// }
|
|
129
|
+
|
|
130
|
+
// async mod(app: Application, req: { data: { body: { signature: { address: string } }; params: { method: string } } }) {
|
|
131
|
+
// log('mod', req);
|
|
132
|
+
|
|
133
|
+
// const user = await app.db.loadUser(req.data.body.signature.address);
|
|
134
|
+
// app.emitAll.playerAction({
|
|
135
|
+
// key: 'moderator-action',
|
|
136
|
+
// createdAt: new Date().getTime() / 1000,
|
|
137
|
+
// address: user.address,
|
|
138
|
+
// username: user.username,
|
|
139
|
+
// method: req.data.params.method,
|
|
140
|
+
// message: `${user.username} called ${req.data.params.method}`,
|
|
141
|
+
// });
|
|
142
|
+
|
|
143
|
+
// return { status: 1 };
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
// async banClient(app: Application, req: { data: { target: string; reason: string; until?: number }; id: string }) {
|
|
147
|
+
// log('banClient', req);
|
|
148
|
+
|
|
149
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
150
|
+
// user.isBanned = true;
|
|
151
|
+
// user.bannedReason = req.data.reason;
|
|
152
|
+
// user.banExpireDate = req.data.until || new Date().getTime() + 100 * 365 * 24 * 60 * 60; // 100 years by default
|
|
153
|
+
|
|
154
|
+
// await app.db.saveUser(user);
|
|
155
|
+
|
|
156
|
+
// app.db.addBanList('evolution', {
|
|
157
|
+
// address: req.data.target,
|
|
158
|
+
// reason: req.data.reason,
|
|
159
|
+
// until: req.data.until,
|
|
160
|
+
// });
|
|
161
|
+
// app.db.saveBanList();
|
|
162
|
+
|
|
163
|
+
// return { status: 1 };
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// async getCharacter(app: Application, req: { data: { address: string }; id: string }) {
|
|
167
|
+
// log('GetCharacterRequest', req);
|
|
168
|
+
|
|
169
|
+
// let character = this.characters[req.data.address];
|
|
170
|
+
// if (!character) {
|
|
171
|
+
// character = await this.fetchCharacter(app, req.data.address);
|
|
172
|
+
// this.characters[req.data.address] = character;
|
|
173
|
+
// }
|
|
174
|
+
|
|
175
|
+
// return { status: 1 };
|
|
176
|
+
// }
|
|
177
|
+
|
|
178
|
+
// private async fetchCharacter(app: Application, address: string) {
|
|
179
|
+
// // Implement character fetching logic here based on your application's needs
|
|
180
|
+
// return {};
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
// async saveRound(app: Application, req: any) {
|
|
184
|
+
// log('SaveRoundRequest', req);
|
|
185
|
+
|
|
186
|
+
// if (!(await isValidRequest(app.web3, req)) && app.db.evolution.modList.includes(req.signature.address)) {
|
|
187
|
+
// log('Round invalid');
|
|
188
|
+
// return { status: 0, message: 'Invalid signature' };
|
|
189
|
+
// return;
|
|
190
|
+
// }
|
|
191
|
+
|
|
192
|
+
// return { status: 1 };
|
|
193
|
+
// }
|
|
194
|
+
// }
|
|
195
|
+
|
|
196
|
+
// export const evolutionService = new EvolutionService();
|
|
197
|
+
|
|
198
|
+
// export const evolutionRouter = t.router({
|
|
199
|
+
// pingRequest: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
200
|
+
// evolutionService.pingRequest(input);
|
|
201
|
+
// }),
|
|
202
|
+
|
|
203
|
+
// pongRequest: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
204
|
+
// evolutionService.pongRequest(input);
|
|
205
|
+
// }),
|
|
206
|
+
|
|
207
|
+
// unbanClient: t.procedure
|
|
208
|
+
// .input(z.object({ data: z.object({ target: z.string() }), id: z.string() }))
|
|
209
|
+
// .mutation(({ input, ctx }) => {
|
|
210
|
+
// evolutionService.unbanClient(ctx.app, input);
|
|
211
|
+
// }),
|
|
212
|
+
|
|
213
|
+
// mod: t.procedure
|
|
214
|
+
// .input(
|
|
215
|
+
// z.object({
|
|
216
|
+
// data: z.object({
|
|
217
|
+
// body: z.object({ signature: z.object({ address: z.string() }) }),
|
|
218
|
+
// params: z.object({ method: z.string() }),
|
|
219
|
+
// }),
|
|
220
|
+
// })
|
|
221
|
+
// )
|
|
222
|
+
// .mutation(({ input, ctx }) => {
|
|
223
|
+
// evolutionService.mod(ctx.app, input);
|
|
224
|
+
// }),
|
|
225
|
+
|
|
226
|
+
// banClient: t.procedure
|
|
227
|
+
// .input(
|
|
228
|
+
// z.object({
|
|
229
|
+
// data: z.object({ target: z.string(), reason: z.string(), until: z.number().optional() }),
|
|
230
|
+
// id: z.string(),
|
|
231
|
+
// })
|
|
232
|
+
// )
|
|
233
|
+
// .mutation(({ input, ctx }) => {
|
|
234
|
+
// evolutionService.banClient(ctx.app, input);
|
|
235
|
+
// }),
|
|
236
|
+
|
|
237
|
+
// getCharacter: t.procedure
|
|
238
|
+
// .input(z.object({ data: z.object({ address: z.string() }), id: z.string() }))
|
|
239
|
+
// .mutation(({ input, ctx }) => {
|
|
240
|
+
// evolutionService.getCharacter(ctx.app, input);
|
|
241
|
+
// }),
|
|
242
|
+
|
|
243
|
+
// saveRound: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
244
|
+
// evolutionService.saveRound(ctx.app, input);
|
|
245
|
+
// }),
|
|
246
|
+
|
|
247
|
+
// // Add more procedures as necessary
|
|
248
|
+
// });
|
|
249
|
+
|
|
250
|
+
// // Add the router type export if necessary
|
|
251
|
+
// export type EvolutionRouter = typeof evolutionRouter;
|
|
252
|
+
|
|
253
|
+
// const shortId = require('shortid');
|
|
254
|
+
|
|
255
|
+
// let CharacterCache = {};
|
|
256
|
+
// const ioCallbacks = {};
|
|
257
|
+
|
|
258
|
+
// async function rsCall(app, realm, name, data = undefined) {
|
|
259
|
+
// try {
|
|
260
|
+
// const id = shortId();
|
|
261
|
+
// const signature =
|
|
262
|
+
// data !== undefined && data !== null
|
|
263
|
+
// ? await getSignedRequest(
|
|
264
|
+
// app.web3,
|
|
265
|
+
// app.secrets.find((s) => s.id === 'evolution-signer'),
|
|
266
|
+
// data
|
|
267
|
+
// )
|
|
268
|
+
// : null;
|
|
269
|
+
|
|
270
|
+
// return new Promise(async (resolve) => {
|
|
271
|
+
// ioCallbacks[id] = {};
|
|
272
|
+
|
|
273
|
+
// ioCallbacks[id].resolve = resolve;
|
|
274
|
+
|
|
275
|
+
// ioCallbacks[id].reqTimeout = setTimeout(function () {
|
|
276
|
+
// log('Request timeout');
|
|
277
|
+
// resolve({ status: 0, message: 'Request timeout' });
|
|
278
|
+
|
|
279
|
+
// delete ioCallbacks[id];
|
|
280
|
+
// }, 60 * 1000);
|
|
281
|
+
|
|
282
|
+
// if (!realm.client.socket?.connected) {
|
|
283
|
+
// log('Not connected to realm server: ' + realm.key);
|
|
284
|
+
// return;
|
|
285
|
+
// }
|
|
286
|
+
|
|
287
|
+
// log('Emit Realm', realm.key, name, { id, data });
|
|
288
|
+
|
|
289
|
+
// realm.client.socket.emit(name, { id, signature, data });
|
|
290
|
+
// });
|
|
291
|
+
// } catch (e) {
|
|
292
|
+
// log(e);
|
|
293
|
+
// }
|
|
294
|
+
// }
|
|
295
|
+
|
|
296
|
+
// function setRealmOffline(realm) {
|
|
297
|
+
// if (realm.status === 'inactive' || realm.updateMode === 'manual') return;
|
|
298
|
+
|
|
299
|
+
// realm.status = 'offline';
|
|
300
|
+
// realm.playerCount = 0;
|
|
301
|
+
// realm.speculatorCount = 0;
|
|
302
|
+
// realm.rewardItemAmount = 0;
|
|
303
|
+
// realm.rewardWinnerAmount = 0;
|
|
304
|
+
// }
|
|
305
|
+
|
|
306
|
+
// async function setRealmConfig(app, realm) {
|
|
307
|
+
// const configRes = (await rsCall(app, app.games.evolution.realms[realm.key], 'SetConfigRequest', {
|
|
308
|
+
// config: { ...app.db.evolution.config, roundId: realm.roundId },
|
|
309
|
+
// })) as any;
|
|
310
|
+
|
|
311
|
+
// if (configRes.status !== 1) {
|
|
312
|
+
// setRealmOffline(realm);
|
|
313
|
+
// return;
|
|
314
|
+
// }
|
|
315
|
+
// }
|
|
316
|
+
|
|
317
|
+
// async function updateRealm(app, realm) {
|
|
318
|
+
// try {
|
|
319
|
+
// realm.games = [];
|
|
320
|
+
|
|
321
|
+
// const infoRes = (await rsCall(app, app.games.evolution.realms[realm.key], 'InfoRequest', { config: {} })) as any; // roundId: realm.roundId
|
|
322
|
+
|
|
323
|
+
// if (!infoRes || infoRes.status !== 1) {
|
|
324
|
+
// setRealmOffline(realm);
|
|
325
|
+
// return;
|
|
326
|
+
// }
|
|
327
|
+
|
|
328
|
+
// log('infoRes', infoRes.data.games);
|
|
329
|
+
|
|
330
|
+
// const { data } = infoRes;
|
|
331
|
+
|
|
332
|
+
// realm.playerCount = data.playerCount;
|
|
333
|
+
// realm.speculatorCount = data.speculatorCount;
|
|
334
|
+
// realm.version = data.version;
|
|
335
|
+
|
|
336
|
+
// realm.games = data.games.map((game) => ({
|
|
337
|
+
// id: game.id,
|
|
338
|
+
// playerCount: game.playerCount,
|
|
339
|
+
// speculatorCount: game.speculatorCount,
|
|
340
|
+
// version: game.version,
|
|
341
|
+
// rewardItemAmount: game.rewardItemAmount,
|
|
342
|
+
// rewardWinnerAmount: game.rewardWinnerAmount,
|
|
343
|
+
// gameMode: game.gameMode,
|
|
344
|
+
// connectedPlayers: game.connectedPlayers,
|
|
345
|
+
// roundId: game.round.id,
|
|
346
|
+
// roundStartedAt: game.round.startedAt,
|
|
347
|
+
// timeLeft: ~~(5 * 60 - (new Date().getTime() / 1000 - game.round.startedAt)),
|
|
348
|
+
// timeLeftText: fancyTimeFormat(5 * 60 - (new Date().getTime() / 1000 - game.round.startedAt)),
|
|
349
|
+
// endpoint: (function () {
|
|
350
|
+
// const url = new URL((process.env.ARKEN_ENV === 'local' ? 'http://' : 'https://') + realm.endpoint);
|
|
351
|
+
// url.port = game.port;
|
|
352
|
+
// return url.toString();
|
|
353
|
+
// })()
|
|
354
|
+
// .replace('http://', '')
|
|
355
|
+
// .replace('https://', '')
|
|
356
|
+
// .replace('/', ''),
|
|
357
|
+
// }));
|
|
358
|
+
|
|
359
|
+
// delete realm.timeLeftFancy;
|
|
360
|
+
|
|
361
|
+
// realm.status = 'online';
|
|
362
|
+
// } catch (e) {
|
|
363
|
+
// log('Error', e);
|
|
364
|
+
|
|
365
|
+
// setRealmOffline(realm);
|
|
366
|
+
// }
|
|
367
|
+
|
|
368
|
+
// // log('Updated server', server)
|
|
369
|
+
|
|
370
|
+
// return realm;
|
|
371
|
+
// }
|
|
372
|
+
|
|
373
|
+
// async function updateRealms(app) {
|
|
374
|
+
// try {
|
|
375
|
+
// log('Updating Evolution realms');
|
|
376
|
+
|
|
377
|
+
// let playerCount = 0;
|
|
378
|
+
|
|
379
|
+
// for (const realm of app.db.evolution.realms) {
|
|
380
|
+
// // if (realm.key.indexOf('ptr') !== -1 || realm.key.indexOf('tournament') !== -1) continue
|
|
381
|
+
// if (realm.status === 'inactive' || realm.updateMode === 'manual') continue;
|
|
382
|
+
|
|
383
|
+
// await updateRealm(app, realm);
|
|
384
|
+
|
|
385
|
+
// const hist = jetpack.read(path.resolve(`./db/evolution/${realm.key}/historical.json`), 'json') || {};
|
|
386
|
+
|
|
387
|
+
// if (!hist.playerCount) hist.playerCount = [];
|
|
388
|
+
|
|
389
|
+
// const oldTime = new Date(hist.playerCount[hist.playerCount.length - 1]?.[0] || 0).getTime();
|
|
390
|
+
// const newTime = new Date().getTime();
|
|
391
|
+
// const diff = newTime - oldTime;
|
|
392
|
+
// if (diff / (1000 * 60 * 60 * 1) > 1) {
|
|
393
|
+
// hist.playerCount.push([newTime, realm.playerCount]);
|
|
394
|
+
// }
|
|
395
|
+
|
|
396
|
+
// jetpack.write(path.resolve(`./db/evolution/${realm.key}/historical.json`), JSON.stringify(hist), {
|
|
397
|
+
// atomic: true,
|
|
398
|
+
// jsonIndent: 0,
|
|
399
|
+
// });
|
|
400
|
+
|
|
401
|
+
// playerCount += realm.playerCount;
|
|
402
|
+
|
|
403
|
+
// log(`Realm ${realm.key} updated`, realm);
|
|
404
|
+
// }
|
|
405
|
+
|
|
406
|
+
// app.db.evolution.playerCount = playerCount;
|
|
407
|
+
|
|
408
|
+
// for (const server of app.db.evolution.servers) {
|
|
409
|
+
// if (server.status === 'inactive' || server.updateMode === 'manual') continue;
|
|
410
|
+
// // if (server.key.indexOf('tournament') !== -1) continue
|
|
411
|
+
|
|
412
|
+
// server.status = 'offline';
|
|
413
|
+
// server.playerCount = 0;
|
|
414
|
+
// }
|
|
415
|
+
|
|
416
|
+
// const evolutionServers = app.db.evolution.realms
|
|
417
|
+
// .filter((r) => r.status !== 'inactive')
|
|
418
|
+
// .map((r) =>
|
|
419
|
+
// r.games.length > 0
|
|
420
|
+
// ? {
|
|
421
|
+
// ...(app.db.evolution.servers.find((e) => e.key === r.key) || {}),
|
|
422
|
+
// ...r.games[0],
|
|
423
|
+
// key: r.key,
|
|
424
|
+
// name: r.name,
|
|
425
|
+
// status: r.status,
|
|
426
|
+
// regionId: r.regionId,
|
|
427
|
+
// }
|
|
428
|
+
// : {}
|
|
429
|
+
// );
|
|
430
|
+
|
|
431
|
+
// for (const evolutionServer of evolutionServers) {
|
|
432
|
+
// const server = app.db.evolution.servers.find((s) => s.key === evolutionServer.key);
|
|
433
|
+
|
|
434
|
+
// if (!server) {
|
|
435
|
+
// if (evolutionServer.key) {
|
|
436
|
+
// app.db.evolution.servers.push(evolutionServer);
|
|
437
|
+
// }
|
|
438
|
+
// continue;
|
|
439
|
+
// }
|
|
440
|
+
|
|
441
|
+
// if (evolutionServer.status === 'inactive' || evolutionServer.updateMode === 'manual') continue;
|
|
442
|
+
|
|
443
|
+
// server.status = evolutionServer.status;
|
|
444
|
+
// server.version = evolutionServer.version;
|
|
445
|
+
// server.rewardItemAmount = evolutionServer.rewardItemAmount;
|
|
446
|
+
// server.rewardWinnerAmount = evolutionServer.rewardWinnerAmount;
|
|
447
|
+
// server.gameMode = evolutionServer.gameMode;
|
|
448
|
+
// server.roundId = evolutionServer.roundId;
|
|
449
|
+
// server.roundStartedAt = evolutionServer.roundStartedAt;
|
|
450
|
+
// server.roundStartedDate = evolutionServer.roundStartedDate;
|
|
451
|
+
// server.timeLeft = evolutionServer.timeLeft;
|
|
452
|
+
// server.timeLeftText = evolutionServer.timeLeftText;
|
|
453
|
+
// server.playerCount = evolutionServer.playerCount;
|
|
454
|
+
// server.speculatorCount = evolutionServer.speculatorCount;
|
|
455
|
+
// server.endpoint = evolutionServer.endpoint;
|
|
456
|
+
// }
|
|
457
|
+
|
|
458
|
+
// jetpack.write(path.resolve('./db/evolution/realms.json'), JSON.stringify(app.db.evolution.realms), {
|
|
459
|
+
// atomic: true,
|
|
460
|
+
// jsonIndent: 0,
|
|
461
|
+
// });
|
|
462
|
+
|
|
463
|
+
// // Update old servers file
|
|
464
|
+
// jetpack.write(path.resolve('./db/evolution/servers.json'), JSON.stringify(app.db.evolution.servers), {
|
|
465
|
+
// atomic: true,
|
|
466
|
+
// jsonIndent: 0,
|
|
467
|
+
// });
|
|
468
|
+
|
|
469
|
+
// log('Realm and server info generated');
|
|
470
|
+
|
|
471
|
+
// // Update overall historics
|
|
472
|
+
// const hist = jetpack.read(path.resolve(`./db/evolution/historical.json`), 'json') || {};
|
|
473
|
+
|
|
474
|
+
// if (!hist.playerCount) hist.playerCount = [];
|
|
475
|
+
|
|
476
|
+
// const oldTime = new Date(hist.playerCount[hist.playerCount.length - 1]?.[0] || 0).getTime();
|
|
477
|
+
// const newTime = new Date().getTime();
|
|
478
|
+
// const diff = newTime - oldTime;
|
|
479
|
+
// if (diff / (1000 * 60 * 60 * 1) > 1) {
|
|
480
|
+
// hist.playerCount.push([newTime, playerCount]);
|
|
481
|
+
// }
|
|
482
|
+
|
|
483
|
+
// jetpack.write(path.resolve(`./db/evolution/historical.json`), JSON.stringify(hist), {
|
|
484
|
+
// atomic: true,
|
|
485
|
+
// jsonIndent: 0,
|
|
486
|
+
// });
|
|
487
|
+
// } catch (e) {
|
|
488
|
+
// log('Error', e);
|
|
489
|
+
// }
|
|
490
|
+
// }
|
|
491
|
+
|
|
492
|
+
// function cleanupClient(client) {
|
|
493
|
+
// log('Cleaning up', client.key);
|
|
494
|
+
|
|
495
|
+
// client.socket?.close();
|
|
496
|
+
// client.isConnected = false;
|
|
497
|
+
// client.isConnecting = false;
|
|
498
|
+
// client.isAuthed = false;
|
|
499
|
+
|
|
500
|
+
// clearTimeout(client.timeout);
|
|
501
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
502
|
+
// clearTimeout(client.pingerTimeout);
|
|
503
|
+
// }
|
|
504
|
+
|
|
505
|
+
// function disconnectClient(client) {
|
|
506
|
+
// log('Disconnecting client', client.key);
|
|
507
|
+
|
|
508
|
+
// cleanupClient(client);
|
|
509
|
+
// }
|
|
510
|
+
|
|
511
|
+
// async function getCharacter(app, address) {
|
|
512
|
+
// const equipment = await app.barracks.getPlayerEquipment(app, address);
|
|
513
|
+
// const meta = await app.barracks.getMetaFromEquipment(app, equipment);
|
|
514
|
+
|
|
515
|
+
// // if (address === '0x1a367CA7bD311F279F1dfAfF1e60c4d797Faa6eb') {
|
|
516
|
+
// // meta[1030] = 100
|
|
517
|
+
// // }
|
|
518
|
+
|
|
519
|
+
// let error;
|
|
520
|
+
// if (meta[1030] > 100) error = `Problem with EvolutionMovementSpeedIncrease: ${address} ${meta[1030]}`;
|
|
521
|
+
// if (meta[1102] > 100) error = `Problem with DeathPenaltyAvoid: ${address} ${meta[1102]}`;
|
|
522
|
+
// if (meta[1104] > 100) error = `Problem with EnergyDecayDecrease: ${address} ${meta[1104]}`;
|
|
523
|
+
// if (meta[1105] > 100) error = `Problem with EnergyDecayIncrease: ${address} ${meta[1105]}`;
|
|
524
|
+
// if (meta[1150] > 100) error = `Problem with WinRewardsIncrease: ${address} ${meta[1150]}`;
|
|
525
|
+
// if (meta[1160] > 100) error = `Problem with WinRewardsDecrease: ${address} ${meta[1160]}`;
|
|
526
|
+
// if (meta[1222] > 100) error = `Problem with IncreaseMovementSpeedOnKill: ${address} ${meta[1222]}`;
|
|
527
|
+
// if (meta[1223] > 100) error = `Problem with EvolveMovementBurst: ${address} ${meta[1223]}`;
|
|
528
|
+
// if (meta[1164] > 100) error = `Problem with DoublePickupChance: ${address} ${meta[1164]}`;
|
|
529
|
+
// if (meta[1219] > 100) error = `Problem with IncreaseHealthOnKill: ${address} ${meta[1219]}`;
|
|
530
|
+
// if (meta[1117] > 100) error = `Problem with SpriteFuelIncrease: ${address} ${meta[1117]}`;
|
|
531
|
+
// if (meta[1118] > 100) error = `Problem with SpriteFuelDecrease: ${address} ${meta[1118]}`;
|
|
532
|
+
|
|
533
|
+
// if (error) {
|
|
534
|
+
// log('Error with character gear:', error);
|
|
535
|
+
// process.exit(6);
|
|
536
|
+
// }
|
|
537
|
+
|
|
538
|
+
// return {
|
|
539
|
+
// equipment,
|
|
540
|
+
// meta,
|
|
541
|
+
// };
|
|
542
|
+
// }
|
|
543
|
+
|
|
544
|
+
// const runes = [
|
|
545
|
+
// 'el',
|
|
546
|
+
// 'eld',
|
|
547
|
+
// 'tir',
|
|
548
|
+
// 'nef',
|
|
549
|
+
// 'ith',
|
|
550
|
+
// 'tal',
|
|
551
|
+
// 'ral',
|
|
552
|
+
// 'ort',
|
|
553
|
+
// 'thul',
|
|
554
|
+
// 'amn',
|
|
555
|
+
// 'sol',
|
|
556
|
+
// 'shael',
|
|
557
|
+
// 'dol',
|
|
558
|
+
// 'hel',
|
|
559
|
+
// 'io',
|
|
560
|
+
// 'lum',
|
|
561
|
+
// 'ko',
|
|
562
|
+
// 'fal',
|
|
563
|
+
// 'lem',
|
|
564
|
+
// 'pul',
|
|
565
|
+
// 'um',
|
|
566
|
+
// 'mal',
|
|
567
|
+
// 'ist',
|
|
568
|
+
// 'gul',
|
|
569
|
+
// 'vex',
|
|
570
|
+
// 'ohm',
|
|
571
|
+
// 'lo',
|
|
572
|
+
// 'sur',
|
|
573
|
+
// 'ber',
|
|
574
|
+
// 'jah',
|
|
575
|
+
// 'cham',
|
|
576
|
+
// 'zod',
|
|
577
|
+
// ];
|
|
578
|
+
|
|
579
|
+
// export async function connectRealm(app, realm) {
|
|
580
|
+
// if (realm.status === 'inactive' || realm.ignore) return;
|
|
581
|
+
|
|
582
|
+
// log('Connecting to realm', realm);
|
|
583
|
+
// const { client } = app.games.evolution.realms[realm.key];
|
|
584
|
+
|
|
585
|
+
// if (client.isConnected || client.socket?.connected) {
|
|
586
|
+
// log(`Realm ${realm.key} already connected, disconnecting`);
|
|
587
|
+
// cleanupClient(client);
|
|
588
|
+
// }
|
|
589
|
+
|
|
590
|
+
// client.isConnecting = true;
|
|
591
|
+
// client.socket = getClientSocket((process.env.ARKEN_ENV === 'local' ? 'http://' : 'https://') + realm.endpoint); // TODO: RS should be running things
|
|
592
|
+
|
|
593
|
+
// client.socket.on('connect', async () => {
|
|
594
|
+
// try {
|
|
595
|
+
// client.isConnected = true;
|
|
596
|
+
|
|
597
|
+
// log('Connected: ' + realm.key);
|
|
598
|
+
|
|
599
|
+
// const res = (await rsCall(app, app.games.evolution.realms[realm.key], 'AuthRequest', 'myverysexykey')) as any;
|
|
600
|
+
|
|
601
|
+
// if (res.status === 1) {
|
|
602
|
+
// client.isAuthed = true;
|
|
603
|
+
|
|
604
|
+
// clearTimeout(client.connectTimeout);
|
|
605
|
+
|
|
606
|
+
// await setRealmConfig(app, realm);
|
|
607
|
+
// await updateRealm(app, realm);
|
|
608
|
+
// }
|
|
609
|
+
|
|
610
|
+
// client.isConnecting = false;
|
|
611
|
+
|
|
612
|
+
// const pinger = async () => {
|
|
613
|
+
// try {
|
|
614
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
615
|
+
|
|
616
|
+
// client.pingReplyTimeout = setTimeout(function () {
|
|
617
|
+
// log(`Realm ${realm.key} didnt respond in time, disconnecting`);
|
|
618
|
+
// cleanupClient(client);
|
|
619
|
+
// }, 70 * 1000);
|
|
620
|
+
|
|
621
|
+
// await rsCall(app, app.games.evolution.realms[realm.key], 'PingRequest');
|
|
622
|
+
|
|
623
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
624
|
+
|
|
625
|
+
// if (!client.isConnected) return;
|
|
626
|
+
|
|
627
|
+
// client.pingerTimeout = setTimeout(async () => await pinger(), 15 * 1000);
|
|
628
|
+
// } catch (e) {
|
|
629
|
+
// log(e);
|
|
630
|
+
// }
|
|
631
|
+
// };
|
|
632
|
+
|
|
633
|
+
// clearTimeout(client.pingerTimeout);
|
|
634
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
635
|
+
|
|
636
|
+
// client.pingerTimeout = setTimeout(async () => await pinger(), 15 * 1000);
|
|
637
|
+
// } catch (e) {
|
|
638
|
+
// log('Error', e);
|
|
639
|
+
// log(`Disconnecting ${realm.key} due to error`);
|
|
640
|
+
// cleanupClient(client);
|
|
641
|
+
// }
|
|
642
|
+
// });
|
|
643
|
+
|
|
644
|
+
// client.socket.on('disconnect', () => {
|
|
645
|
+
// log('Disconnected: ' + realm.key);
|
|
646
|
+
// cleanupClient(client);
|
|
647
|
+
// });
|
|
648
|
+
|
|
649
|
+
// // client.socket.on('banClient', async function (req) {
|
|
650
|
+
// // console.log(req)
|
|
651
|
+
// // try {
|
|
652
|
+
// // log('Ban', realm.key, req)
|
|
653
|
+
|
|
654
|
+
// // if (await isValidRequest(app.web3, req) && app.db.evolution.modList.includes(req.signature.address)) {
|
|
655
|
+
// // app.db.addBanList('evolution', req.data.target)
|
|
656
|
+
|
|
657
|
+
// // app.db.saveBanList()
|
|
658
|
+
|
|
659
|
+
// // app.realm.emitAll('BanUserRequest', {
|
|
660
|
+
// // signature: await getSignedRequest(app.web3, app.secrets, md5(JSON.stringify({ target: req.data.target }))),
|
|
661
|
+
// // data: {
|
|
662
|
+
// // target: req.data.target
|
|
663
|
+
// // }
|
|
664
|
+
// // })
|
|
665
|
+
|
|
666
|
+
// // client.socket.emit('BanUserResponse', {
|
|
667
|
+
// // id: req.id,
|
|
668
|
+
// // data: { status: 1 }
|
|
669
|
+
// // })
|
|
670
|
+
// // } else {
|
|
671
|
+
// // client.socket.emit('BanUserResponse', {
|
|
672
|
+
// // id: req.id,
|
|
673
|
+
// // data: { status: 0, message: 'Invalid signature' }
|
|
674
|
+
// // })
|
|
675
|
+
// // }
|
|
676
|
+
// // } catch (e) {
|
|
677
|
+
// // log('Error', e)
|
|
678
|
+
|
|
679
|
+
// // client.socket.emit('BanUserResponse', {
|
|
680
|
+
// // id: req.id,
|
|
681
|
+
// // data: { status: 0, message: e }
|
|
682
|
+
// // })
|
|
683
|
+
// // }
|
|
684
|
+
// // })
|
|
685
|
+
|
|
686
|
+
// client.socket.on('PingRequest', function (msg) {
|
|
687
|
+
// log('PingRequest', realm.key, msg);
|
|
688
|
+
|
|
689
|
+
// client.socket.emit('PingResponse');
|
|
690
|
+
// });
|
|
691
|
+
|
|
692
|
+
// client.socket.on('PongRequest', function (msg) {
|
|
693
|
+
// log('PongRequest', realm.key, msg);
|
|
694
|
+
|
|
695
|
+
// client.socket.emit('PongResponse');
|
|
696
|
+
// });
|
|
697
|
+
|
|
698
|
+
// client.socket.on('unbanClient', async function (req) {
|
|
699
|
+
// try {
|
|
700
|
+
// log('Ban', realm.key, req);
|
|
701
|
+
|
|
702
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
703
|
+
|
|
704
|
+
// delete user.isBanned;
|
|
705
|
+
// delete user.bannedReason;
|
|
706
|
+
|
|
707
|
+
// await app.db.saveUser(user);
|
|
708
|
+
|
|
709
|
+
// app.db.removeBanList('evolution', req.data.target);
|
|
710
|
+
// app.db.saveBanList();
|
|
711
|
+
|
|
712
|
+
// app.realm.emitAll('UnbanUserRequest', {
|
|
713
|
+
// data: {
|
|
714
|
+
// target: req.data.target,
|
|
715
|
+
// },
|
|
716
|
+
// });
|
|
717
|
+
|
|
718
|
+
// client.socket.emit('UnbanClientResponse', {
|
|
719
|
+
// id: req.id,
|
|
720
|
+
// data: { status: 1 },
|
|
721
|
+
// });
|
|
722
|
+
// } catch (e) {
|
|
723
|
+
// log('Error', e);
|
|
724
|
+
|
|
725
|
+
// client.socket.emit('UnbanClientResponse', {
|
|
726
|
+
// id: req.id,
|
|
727
|
+
// data: { status: 0, message: e },
|
|
728
|
+
// });
|
|
729
|
+
// }
|
|
730
|
+
// });
|
|
731
|
+
|
|
732
|
+
// client.socket.on('mod', async function (req) {
|
|
733
|
+
// try {
|
|
734
|
+
// log('mod', realm.key, req);
|
|
735
|
+
|
|
736
|
+
// const user = await app.db.loadUser(req.data.body.signature.address);
|
|
737
|
+
|
|
738
|
+
// app.api.emitAll('playerAction', {
|
|
739
|
+
// key: 'moderator-action',
|
|
740
|
+
// createdAt: new Date().getTime() / 1000,
|
|
741
|
+
// address: user.address,
|
|
742
|
+
// username: user.username,
|
|
743
|
+
// method: req.data.params.method,
|
|
744
|
+
// realmKey: realm.key,
|
|
745
|
+
// message: `${user.username} called ${req.data.params.method}`,
|
|
746
|
+
// });
|
|
747
|
+
|
|
748
|
+
// client.socket.emit('ModResponse', {
|
|
749
|
+
// id: req.id,
|
|
750
|
+
// data: { status: 1 },
|
|
751
|
+
// });
|
|
752
|
+
// } catch (e) {
|
|
753
|
+
// log('Error', e);
|
|
754
|
+
|
|
755
|
+
// client.socket.emit('ModResponse', {
|
|
756
|
+
// id: req.id,
|
|
757
|
+
// data: { status: 0, message: e },
|
|
758
|
+
// });
|
|
759
|
+
// }
|
|
760
|
+
// });
|
|
761
|
+
|
|
762
|
+
// client.socket.on('banClient', async function (req) {
|
|
763
|
+
// try {
|
|
764
|
+
// log('banClient', realm.key, req);
|
|
765
|
+
|
|
766
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
767
|
+
|
|
768
|
+
// user.isBanned = true;
|
|
769
|
+
// user.bannedReason = req.data.reason;
|
|
770
|
+
// user.bannedUntil = req.data.until ? parseInt(req.data.until) : new Date().getTime() + 100 * 365 * 24 * 60 * 60; // 100 year ban by default
|
|
771
|
+
|
|
772
|
+
// await app.db.saveUser(user);
|
|
773
|
+
|
|
774
|
+
// app.db.addBanList('evolution', { address: req.data.target, reason: req.data.reason, until: req.data.until });
|
|
775
|
+
// app.db.saveBanList();
|
|
776
|
+
|
|
777
|
+
// app.realm.emitAll('BanUserRequest', {
|
|
778
|
+
// data: {
|
|
779
|
+
// target: req.data.target,
|
|
780
|
+
// createdAt: new Date().getTime(),
|
|
781
|
+
// bannedUntil: user.bannedUntil,
|
|
782
|
+
// bannedReason: user.bannedReason,
|
|
783
|
+
// },
|
|
784
|
+
// });
|
|
785
|
+
|
|
786
|
+
// client.socket.emit('BanPlayerResponse', {
|
|
787
|
+
// id: req.id,
|
|
788
|
+
// data: { status: 1 },
|
|
789
|
+
// });
|
|
790
|
+
// } catch (e) {
|
|
791
|
+
// log('Error', e);
|
|
792
|
+
|
|
793
|
+
// client.socket.emit('BanPlayerResponse', {
|
|
794
|
+
// id: req.id,
|
|
795
|
+
// data: { status: 0, message: e },
|
|
796
|
+
// });
|
|
797
|
+
// }
|
|
798
|
+
// });
|
|
799
|
+
|
|
800
|
+
// client.socket.on('reportClient', function (msg) {
|
|
801
|
+
// log('reportClient', realm.key, msg);
|
|
802
|
+
|
|
803
|
+
// const { currentGamePlayers, currentPlayer, reportedPlayer } = msg;
|
|
804
|
+
|
|
805
|
+
// if (currentPlayer.name.indexOf('Guest') !== -1 || currentPlayer.name.indexOf('Unknown') !== -1) return; // No guest reports
|
|
806
|
+
|
|
807
|
+
// if (!app.db.evolution.reportList[reportedPlayer.address]) app.db.evolution.reportList[reportedPlayer.address] = [];
|
|
808
|
+
|
|
809
|
+
// if (!app.db.evolution.reportList[reportedPlayer.address].includes(currentPlayer.address))
|
|
810
|
+
// app.db.evolution.reportList[reportedPlayer.address].push(currentPlayer.address);
|
|
811
|
+
|
|
812
|
+
// // if (app.db.evolution.reportList[reportedPlayer.address].length >= 6) {
|
|
813
|
+
// // app.db.evolution.banList.push(reportedPlayer.address)
|
|
814
|
+
|
|
815
|
+
// // disconnectPlayer(reportedPlayer)
|
|
816
|
+
// // // emitDirect(client.sockets[reportedPlayer.id], 'OnBanned', true)
|
|
817
|
+
// // return
|
|
818
|
+
// // }
|
|
819
|
+
|
|
820
|
+
// // if (currentGamePlayers.length >= 4) {
|
|
821
|
+
// // const reportsFromCurrentGamePlayers = app.db.evolution.reportList[reportedPlayer.address].filter(function(n) {
|
|
822
|
+
// // return currentGamePlayers.indexOf(n) !== -1;
|
|
823
|
+
// // })
|
|
824
|
+
|
|
825
|
+
// // if (reportsFromCurrentGamePlayers.length >= currentGamePlayers.length / 3) {
|
|
826
|
+
// // app.db.evolution.banList.push(reportedPlayer.address)
|
|
827
|
+
|
|
828
|
+
// // disconnectPlayer(reportedPlayer)
|
|
829
|
+
// // // emitDirect(client.sockets[reportedPlayer.id], 'OnBanned', true)
|
|
830
|
+
// // return
|
|
831
|
+
// // }
|
|
832
|
+
// // }
|
|
833
|
+
|
|
834
|
+
// // Relay the report to connected realm servers
|
|
835
|
+
// });
|
|
836
|
+
|
|
837
|
+
// client.socket.on('GetCharacterRequest', async function (req) {
|
|
838
|
+
// log('GetCharacterRequest', req);
|
|
839
|
+
|
|
840
|
+
// try {
|
|
841
|
+
// let character = CharacterCache[req.data.address];
|
|
842
|
+
|
|
843
|
+
// if (!character) {
|
|
844
|
+
// // if (req.data.address === '0x1a367CA7bD311F279F1dfAfF1e60c4d797Faa6eb') {
|
|
845
|
+
// // meta[1030] = 100
|
|
846
|
+
// // }
|
|
847
|
+
|
|
848
|
+
// // if (req.data.address === '0x6f756AFaC862A2486f4c1C96b46E00A98a70bEA2') {
|
|
849
|
+
// // meta[1030] = 100
|
|
850
|
+
// // }
|
|
851
|
+
|
|
852
|
+
// character = await getCharacter(app, req.data.address);
|
|
853
|
+
|
|
854
|
+
// CharacterCache[req.data.address] = character;
|
|
855
|
+
// }
|
|
856
|
+
|
|
857
|
+
// log('GetCharacterResponse', character);
|
|
858
|
+
|
|
859
|
+
// client.socket.emit('GetCharacterResponse', {
|
|
860
|
+
// id: req.id,
|
|
861
|
+
// data: { status: 1, character },
|
|
862
|
+
// });
|
|
863
|
+
// } catch (e) {
|
|
864
|
+
// client.socket.emit('GetCharacterResponse', {
|
|
865
|
+
// id: req.id,
|
|
866
|
+
// data: { status: 0, message: 'Error' },
|
|
867
|
+
// });
|
|
868
|
+
// }
|
|
869
|
+
// });
|
|
870
|
+
|
|
871
|
+
// client.socket.on('SaveRoundRequest', async function (req) {
|
|
872
|
+
// // Iterate the items found, add to user.evolution.rewards
|
|
873
|
+
// // Itereate the runes found, add to user.evolution.runes
|
|
874
|
+
// // Iterate the winners, add to the user.evolution.runes
|
|
875
|
+
// // Add winning stats to user.evolution
|
|
876
|
+
// try {
|
|
877
|
+
// log('SaveRoundRequest', realm.key, req);
|
|
878
|
+
|
|
879
|
+
// if (!(await isValidRequest(app.web3, req)) && app.db.evolution.modList.includes(req.signature.address)) {
|
|
880
|
+
// log('Round invalid');
|
|
881
|
+
|
|
882
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
883
|
+
// id: req.id,
|
|
884
|
+
// data: { status: 0, message: 'Invalid signature' },
|
|
885
|
+
// });
|
|
886
|
+
// return;
|
|
887
|
+
// }
|
|
888
|
+
|
|
889
|
+
// if (!req.data.lastClients) {
|
|
890
|
+
// log('Round no clients');
|
|
891
|
+
|
|
892
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
893
|
+
// id: req.id,
|
|
894
|
+
// data: { status: 0, message: 'Error processing' },
|
|
895
|
+
// });
|
|
896
|
+
// return;
|
|
897
|
+
// }
|
|
898
|
+
|
|
899
|
+
// if (req.data.round.winners.length === 0) {
|
|
900
|
+
// realm.roundId += 1;
|
|
901
|
+
|
|
902
|
+
// log('Round skipped');
|
|
903
|
+
|
|
904
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
905
|
+
// id: req.id,
|
|
906
|
+
// data: { status: 1 },
|
|
907
|
+
// });
|
|
908
|
+
// return;
|
|
909
|
+
// }
|
|
910
|
+
|
|
911
|
+
// if (req.data.rewardWinnerAmount > app.db.evolution.config.rewardWinnerAmountMax) {
|
|
912
|
+
// log(req.data.rewardWinnerAmount, app.db.evolution.config.rewardWinnerAmountMax);
|
|
913
|
+
// throw new Error('Big problem with reward amount');
|
|
914
|
+
// }
|
|
915
|
+
|
|
916
|
+
// let totalLegitPlayers = 0;
|
|
917
|
+
|
|
918
|
+
// for (const client of req.data.lastClients) {
|
|
919
|
+
// if (client.name.indexOf('Guest') !== -1 || client.name.indexOf('Unknown') !== -1) continue;
|
|
920
|
+
|
|
921
|
+
// if (
|
|
922
|
+
// (client.powerups > 100 && client.kills > 1) ||
|
|
923
|
+
// (client.evolves > 20 && client.powerups > 200) ||
|
|
924
|
+
// (client.rewards > 3 && client.powerups > 200) ||
|
|
925
|
+
// client.evolves > 100 ||
|
|
926
|
+
// client.points > 1000
|
|
927
|
+
// ) {
|
|
928
|
+
// totalLegitPlayers += 1;
|
|
929
|
+
// }
|
|
930
|
+
// }
|
|
931
|
+
|
|
932
|
+
// if (totalLegitPlayers === 0) {
|
|
933
|
+
// totalLegitPlayers = 1;
|
|
934
|
+
// }
|
|
935
|
+
|
|
936
|
+
// if (req.data.rewardWinnerAmount > app.db.evolution.config.rewardWinnerAmountPerLegitPlayer * totalLegitPlayers) {
|
|
937
|
+
// log(
|
|
938
|
+
// req.data.rewardWinnerAmount,
|
|
939
|
+
// app.db.evolution.config.rewardWinnerAmountPerLegitPlayer,
|
|
940
|
+
// totalLegitPlayers,
|
|
941
|
+
// req.data.lastClients.length,
|
|
942
|
+
// JSON.stringify(req.data.lastClients)
|
|
943
|
+
// );
|
|
944
|
+
// throw new Error('Big problem with reward amount 2');
|
|
945
|
+
// }
|
|
946
|
+
|
|
947
|
+
// if (req.data.roundId > realm.roundId) {
|
|
948
|
+
// realm.roundId = req.data.roundId;
|
|
949
|
+
// } else if (req.data.roundId < realm.roundId) {
|
|
950
|
+
// const err = `Round id too low (realm.roundId = ${realm.roundId})`;
|
|
951
|
+
|
|
952
|
+
// log(err);
|
|
953
|
+
|
|
954
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
955
|
+
// id: req.id,
|
|
956
|
+
// data: { status: 0, message: err },
|
|
957
|
+
// });
|
|
958
|
+
|
|
959
|
+
// await setRealmConfig(app, realm);
|
|
960
|
+
|
|
961
|
+
// return;
|
|
962
|
+
// } else {
|
|
963
|
+
// realm.roundId += 1;
|
|
964
|
+
// }
|
|
965
|
+
|
|
966
|
+
// // if (req.data.roundId > realm.roundId) {
|
|
967
|
+
// // client.socket.emit('SaveRoundResponse', {
|
|
968
|
+
// // id: req.id,
|
|
969
|
+
// // data: { status: 0, message: 'Invalid round id' }
|
|
970
|
+
// // })
|
|
971
|
+
// // return
|
|
972
|
+
// // }
|
|
973
|
+
|
|
974
|
+
// const rewardWinnerMap = {
|
|
975
|
+
// 0: Math.round(req.data.rewardWinnerAmount * 1 * 1000) / 1000,
|
|
976
|
+
// 1: Math.round(req.data.rewardWinnerAmount * 0.25 * 1000) / 1000,
|
|
977
|
+
// 2: Math.round(req.data.rewardWinnerAmount * 0.15 * 1000) / 1000,
|
|
978
|
+
// 3: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
979
|
+
// 4: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
980
|
+
// 5: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
981
|
+
// 6: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
982
|
+
// 7: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
983
|
+
// 8: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
984
|
+
// 9: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
985
|
+
// };
|
|
986
|
+
|
|
987
|
+
// // const users = []
|
|
988
|
+
|
|
989
|
+
// // Iterate the winners, determine the winning amounts, validate, save to user rewards
|
|
990
|
+
// // Iterate all players and save their log / stats
|
|
991
|
+
|
|
992
|
+
// const removeDupes2 = (list) => {
|
|
993
|
+
// const seen = {};
|
|
994
|
+
// return list.filter(function (item) {
|
|
995
|
+
// // console.log(item)
|
|
996
|
+
// const k1 = item.address;
|
|
997
|
+
// const exists = seen.hasOwnProperty(k1);
|
|
998
|
+
|
|
999
|
+
// if (!exists) {
|
|
1000
|
+
// seen[k1] = true;
|
|
1001
|
+
// }
|
|
1002
|
+
|
|
1003
|
+
// return !exists;
|
|
1004
|
+
// });
|
|
1005
|
+
// };
|
|
1006
|
+
|
|
1007
|
+
// req.data.round.players = removeDupes2(req.data.round.players); // [...new Set(req.data.round.players.map(obj => obj.key)) ] //
|
|
1008
|
+
|
|
1009
|
+
// const winners = req.data.round.winners.slice(0, 10);
|
|
1010
|
+
|
|
1011
|
+
// const rewardTweaks = {};
|
|
1012
|
+
|
|
1013
|
+
// for (const winner of winners) {
|
|
1014
|
+
// let character = CharacterCache[winner.address];
|
|
1015
|
+
|
|
1016
|
+
// if (!character) {
|
|
1017
|
+
// console.log('Getting char data');
|
|
1018
|
+
// character = await getCharacter(app, winner.address);
|
|
1019
|
+
// console.log('Got char data');
|
|
1020
|
+
|
|
1021
|
+
// CharacterCache[winner.address] = character;
|
|
1022
|
+
// }
|
|
1023
|
+
|
|
1024
|
+
// // if (character?.meta?.[1173] > 0) {
|
|
1025
|
+
// // const portion = 0.05
|
|
1026
|
+
|
|
1027
|
+
// // for (const kill of winner.log.kills) {
|
|
1028
|
+
// // const target = req.data.round.players.filter(p => p.hash === kill)
|
|
1029
|
+
|
|
1030
|
+
// // if (target?.address) {
|
|
1031
|
+
// // if (!rewardTweaks[target.address]) rewardTweaks[target.address] = 0
|
|
1032
|
+
// // if (!rewardTweaks[winner.address]) rewardTweaks[winner.address] = 0
|
|
1033
|
+
|
|
1034
|
+
// // rewardTweaks[target.address] -= portion
|
|
1035
|
+
// // rewardTweaks[winner.address] += portion
|
|
1036
|
+
// // }
|
|
1037
|
+
// // }
|
|
1038
|
+
// // }
|
|
1039
|
+
// }
|
|
1040
|
+
|
|
1041
|
+
// for (const player of req.data.round.players) {
|
|
1042
|
+
// console.log('Loading user');
|
|
1043
|
+
// const user = await app.db.loadUser(player.address);
|
|
1044
|
+
// console.log('Loaded user');
|
|
1045
|
+
// const now = new Date().getTime() / 1000;
|
|
1046
|
+
|
|
1047
|
+
// if (user.lastGamePlayed > now - 4 * 60) continue; // Make sure this player isn't in 2 games or somehow getting double rewards
|
|
1048
|
+
|
|
1049
|
+
// if (typeof user.username === 'object' || !user.username) user.username = await getUsername(user.address);
|
|
1050
|
+
|
|
1051
|
+
// if (!user.username) continue; // Make sure cant earn without a character
|
|
1052
|
+
|
|
1053
|
+
// app.db.setUserActive(user);
|
|
1054
|
+
|
|
1055
|
+
// if (player.killStreak >= 10) {
|
|
1056
|
+
// app.api.emitAll('PlayerAction', {
|
|
1057
|
+
// key: 'evolution1-killstreak',
|
|
1058
|
+
// createdAt: new Date().getTime() / 1000,
|
|
1059
|
+
// address: user.address,
|
|
1060
|
+
// username: user.username,
|
|
1061
|
+
// message: `${user.username} got a ${player.killStreak} killstreak in Evolution`,
|
|
1062
|
+
// });
|
|
1063
|
+
// app.notices.add('evolution1-killstreak', {
|
|
1064
|
+
// key: 'evolution1-killstreak',
|
|
1065
|
+
// address: user.address,
|
|
1066
|
+
// username: user.username,
|
|
1067
|
+
// message: `${user.username} got a ${player.killStreak} killstreak in Evolution`,
|
|
1068
|
+
// });
|
|
1069
|
+
// }
|
|
1070
|
+
|
|
1071
|
+
// for (const pickup of player.pickups) {
|
|
1072
|
+
// if (pickup.type === 'rune') {
|
|
1073
|
+
// // TODO: change to authoritative
|
|
1074
|
+
// if (
|
|
1075
|
+
// pickup.quantity >
|
|
1076
|
+
// req.data.round.players.length * app.db.evolution.config.rewardItemAmountPerLegitPlayer * 2
|
|
1077
|
+
// ) {
|
|
1078
|
+
// log(
|
|
1079
|
+
// pickup.quantity,
|
|
1080
|
+
// app.db.evolution.config.rewardItemAmountPerLegitPlayer,
|
|
1081
|
+
// req.data.round.players.length,
|
|
1082
|
+
// JSON.stringify(req.data.round.players)
|
|
1083
|
+
// );
|
|
1084
|
+
// throw new Error('Big problem with item reward amount');
|
|
1085
|
+
// }
|
|
1086
|
+
|
|
1087
|
+
// if (pickup.quantity > req.data.round.players.length * app.db.evolution.config.rewardItemAmountMax) {
|
|
1088
|
+
// log(pickup.quantity, req.data.round.players.length, app.db.evolution.config.rewardItemAmountMax);
|
|
1089
|
+
// throw new Error('Big problem with item reward amount 2');
|
|
1090
|
+
// }
|
|
1091
|
+
|
|
1092
|
+
// const runeSymbol = pickup.rewardItemName.toLowerCase();
|
|
1093
|
+
|
|
1094
|
+
// if (!runes.includes(runeSymbol)) {
|
|
1095
|
+
// continue;
|
|
1096
|
+
// }
|
|
1097
|
+
|
|
1098
|
+
// if (!user.rewards.runes[runeSymbol] || user.rewards.runes[runeSymbol] < 0.000000001) {
|
|
1099
|
+
// user.rewards.runes[runeSymbol] = 0;
|
|
1100
|
+
// }
|
|
1101
|
+
|
|
1102
|
+
// user.rewards.runes[runeSymbol] += pickup.quantity;
|
|
1103
|
+
|
|
1104
|
+
// if (!user.lifetimeRewards.runes[runeSymbol] || user.lifetimeRewards.runes[runeSymbol] < 0.000000001) {
|
|
1105
|
+
// user.lifetimeRewards.runes[runeSymbol] = 0;
|
|
1106
|
+
// }
|
|
1107
|
+
|
|
1108
|
+
// user.lifetimeRewards.runes[runeSymbol] += pickup.quantity;
|
|
1109
|
+
|
|
1110
|
+
// app.db.evolution.config.itemRewards.runes[runeSymbol.toLowerCase()] -= pickup.quantity;
|
|
1111
|
+
|
|
1112
|
+
// app.db.oracle.outflow.evolutionRewards.tokens.week[runeSymbol.toLowerCase()] += pickup.quantity;
|
|
1113
|
+
// } else {
|
|
1114
|
+
// user.rewards.items[pickup.id] = {
|
|
1115
|
+
// name: pickup.name,
|
|
1116
|
+
// rarity: pickup.rarity,
|
|
1117
|
+
// quantity: pickup.quantity,
|
|
1118
|
+
// };
|
|
1119
|
+
|
|
1120
|
+
// user.lifetimeRewards.items[pickup.id] = {
|
|
1121
|
+
// name: pickup.name,
|
|
1122
|
+
// rarity: pickup.rarity,
|
|
1123
|
+
// quantity: pickup.quantity,
|
|
1124
|
+
// };
|
|
1125
|
+
// }
|
|
1126
|
+
|
|
1127
|
+
// // user.rewardTracking.push(req.tracking)
|
|
1128
|
+
// }
|
|
1129
|
+
|
|
1130
|
+
// user.lastGamePlayed = now;
|
|
1131
|
+
|
|
1132
|
+
// if (!user.evolution.hashes) user.evolution.hashes = [];
|
|
1133
|
+
// if (!user.evolution.hashes.includes(player.hash)) user.evolution.hashes.push(player.hash);
|
|
1134
|
+
|
|
1135
|
+
// user.evolution.hashes = user.evolution.hashes.filter(function (item, pos) {
|
|
1136
|
+
// return user.evolution.hashes.indexOf(item) === pos;
|
|
1137
|
+
// });
|
|
1138
|
+
|
|
1139
|
+
// // users.push(user)
|
|
1140
|
+
|
|
1141
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.names)
|
|
1142
|
+
// app.games.evolution.realms[realm.key].leaderboard.names = {};
|
|
1143
|
+
|
|
1144
|
+
// app.games.evolution.realms[realm.key].leaderboard.names[user.address] = user.username;
|
|
1145
|
+
|
|
1146
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.raw.points[user.address]) {
|
|
1147
|
+
// // 'orbs', 'revenges', 'rounds', 'wins', 'timeSpent', 'winRatio', 'killDeathRatio', 'roundPointRatio', 'averageLatency'
|
|
1148
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.monetary[user.address] = 0;
|
|
1149
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.wins[user.address] = 0;
|
|
1150
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rounds[user.address] = 0;
|
|
1151
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.kills[user.address] = 0;
|
|
1152
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.points[user.address] = 0;
|
|
1153
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.deaths[user.address] = 0;
|
|
1154
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.powerups[user.address] = 0;
|
|
1155
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.evolves[user.address] = 0;
|
|
1156
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rewards[user.address] = 0;
|
|
1157
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.pickups[user.address] = 0;
|
|
1158
|
+
// }
|
|
1159
|
+
|
|
1160
|
+
// // Update leaderboard stats
|
|
1161
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rounds[user.address] += 1;
|
|
1162
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.kills[user.address] += player.kills;
|
|
1163
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.points[user.address] += player.points;
|
|
1164
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.deaths[user.address] += player.deaths;
|
|
1165
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.powerups[user.address] += player.powerups;
|
|
1166
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.evolves[user.address] += player.evolves;
|
|
1167
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rewards[user.address] += player.rewards;
|
|
1168
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.pickups[user.address] += player.pickups.length;
|
|
1169
|
+
|
|
1170
|
+
// if (!app.games.evolution.global.leaderboard.names) app.games.evolution.global.leaderboard.names = {};
|
|
1171
|
+
|
|
1172
|
+
// app.games.evolution.global.leaderboard.names[user.address] = user.username;
|
|
1173
|
+
|
|
1174
|
+
// if (!app.games.evolution.global.leaderboard.raw.points[user.address]) {
|
|
1175
|
+
// // 'orbs', 'revenges', 'rounds', 'wins', 'timeSpent', 'winRatio', 'killDeathRatio', 'roundPointRatio', 'averageLatency'
|
|
1176
|
+
// app.games.evolution.global.leaderboard.raw.monetary[user.address] = 0;
|
|
1177
|
+
// app.games.evolution.global.leaderboard.raw.wins[user.address] = 0;
|
|
1178
|
+
// app.games.evolution.global.leaderboard.raw.rounds[user.address] = 0;
|
|
1179
|
+
// app.games.evolution.global.leaderboard.raw.kills[user.address] = 0;
|
|
1180
|
+
// app.games.evolution.global.leaderboard.raw.points[user.address] = 0;
|
|
1181
|
+
// app.games.evolution.global.leaderboard.raw.deaths[user.address] = 0;
|
|
1182
|
+
// app.games.evolution.global.leaderboard.raw.powerups[user.address] = 0;
|
|
1183
|
+
// app.games.evolution.global.leaderboard.raw.evolves[user.address] = 0;
|
|
1184
|
+
// app.games.evolution.global.leaderboard.raw.rewards[user.address] = 0;
|
|
1185
|
+
// app.games.evolution.global.leaderboard.raw.pickups[user.address] = 0;
|
|
1186
|
+
// }
|
|
1187
|
+
|
|
1188
|
+
// // Update leaderboard stats
|
|
1189
|
+
// app.games.evolution.global.leaderboard.raw.rounds[user.address] += 1;
|
|
1190
|
+
// app.games.evolution.global.leaderboard.raw.kills[user.address] += player.kills;
|
|
1191
|
+
// app.games.evolution.global.leaderboard.raw.points[user.address] += player.points;
|
|
1192
|
+
// app.games.evolution.global.leaderboard.raw.deaths[user.address] += player.deaths;
|
|
1193
|
+
// app.games.evolution.global.leaderboard.raw.powerups[user.address] += player.powerups;
|
|
1194
|
+
// app.games.evolution.global.leaderboard.raw.evolves[user.address] += player.evolves;
|
|
1195
|
+
// app.games.evolution.global.leaderboard.raw.rewards[user.address] += player.rewards;
|
|
1196
|
+
// app.games.evolution.global.leaderboard.raw.pickups[user.address] += player.pickups.length;
|
|
1197
|
+
|
|
1198
|
+
// if (winners.find((winner) => winner.address === player.address)) {
|
|
1199
|
+
// const index = winners.findIndex((winner) => winner.address === player.address);
|
|
1200
|
+
// // const player = req.data.round.winners[index]
|
|
1201
|
+
// // const user = users.find(u => u.address === player.address)
|
|
1202
|
+
|
|
1203
|
+
// // if (!user) continue // He wasn't valid
|
|
1204
|
+
// if (user.username) {
|
|
1205
|
+
// // Make sure cant earn without a character
|
|
1206
|
+
// // if (req.data.round.winners[0].address === player.address) {
|
|
1207
|
+
// let character = CharacterCache[player.address];
|
|
1208
|
+
|
|
1209
|
+
// if (!character) {
|
|
1210
|
+
// console.log('Getting char data');
|
|
1211
|
+
// character = await getCharacter(app, player.address);
|
|
1212
|
+
// console.log('Got char data');
|
|
1213
|
+
|
|
1214
|
+
// CharacterCache[player.address] = character;
|
|
1215
|
+
// }
|
|
1216
|
+
|
|
1217
|
+
// const WinRewardsIncrease = character?.meta?.[1150] || 0;
|
|
1218
|
+
// const WinRewardsDecrease = character?.meta?.[1160] || 0;
|
|
1219
|
+
|
|
1220
|
+
// console.log('bbbb', rewardWinnerMap[index]);
|
|
1221
|
+
// const rewardMultiplier = 1 + (WinRewardsIncrease - WinRewardsDecrease) / 100;
|
|
1222
|
+
|
|
1223
|
+
// if (rewardMultiplier > 2 || rewardMultiplier < 0) {
|
|
1224
|
+
// log(
|
|
1225
|
+
// 'Error with reward multiplier.. bad things happened: ',
|
|
1226
|
+
// rewardMultiplier,
|
|
1227
|
+
// rewardMultiplier,
|
|
1228
|
+
// WinRewardsDecrease
|
|
1229
|
+
// );
|
|
1230
|
+
// process.exit(5);
|
|
1231
|
+
// }
|
|
1232
|
+
|
|
1233
|
+
// rewardWinnerMap[index] *= rewardMultiplier;
|
|
1234
|
+
// console.log('cccc', rewardWinnerMap[index]);
|
|
1235
|
+
// // }
|
|
1236
|
+
|
|
1237
|
+
// if (!user.rewards.runes['zod']) {
|
|
1238
|
+
// user.rewards.runes['zod'] = 0;
|
|
1239
|
+
// }
|
|
1240
|
+
|
|
1241
|
+
// if (user.rewards.runes['zod'] < 0) {
|
|
1242
|
+
// user.rewards.runes['zod'] = 0;
|
|
1243
|
+
// }
|
|
1244
|
+
|
|
1245
|
+
// user.rewards.runes['zod'] += rewardWinnerMap[index];
|
|
1246
|
+
|
|
1247
|
+
// if (!user.lifetimeRewards.runes['zod']) {
|
|
1248
|
+
// user.lifetimeRewards.runes['zod'] = 0;
|
|
1249
|
+
// }
|
|
1250
|
+
|
|
1251
|
+
// user.lifetimeRewards.runes['zod'] += rewardWinnerMap[index];
|
|
1252
|
+
|
|
1253
|
+
// app.db.oracle.outflow.evolutionRewards.tokens.week['zod'] += rewardWinnerMap[index];
|
|
1254
|
+
|
|
1255
|
+
// app.games.evolution.global.leaderboard.raw.monetary[user.address] += rewardWinnerMap[index];
|
|
1256
|
+
|
|
1257
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.monetary[user.address] += rewardWinnerMap[index];
|
|
1258
|
+
|
|
1259
|
+
// app.api.emitAll('PlayerAction', {
|
|
1260
|
+
// key: 'evolution1-winner',
|
|
1261
|
+
// createdAt: new Date().getTime() / 1000,
|
|
1262
|
+
// address: user.address,
|
|
1263
|
+
// username: user.username,
|
|
1264
|
+
// realmKey: realm.key,
|
|
1265
|
+
// placement: index + 1,
|
|
1266
|
+
// message: `${user.username} placed #${index + 1} for ${rewardWinnerMap[index].toFixed(
|
|
1267
|
+
// 4
|
|
1268
|
+
// )} ZOD in Evolution`,
|
|
1269
|
+
// });
|
|
1270
|
+
|
|
1271
|
+
// if (rewardWinnerMap[index] > 0.1) {
|
|
1272
|
+
// app.notices.add('evolution1-winner', {
|
|
1273
|
+
// key: 'evolution1-winner',
|
|
1274
|
+
// address: user.address,
|
|
1275
|
+
// username: user.username,
|
|
1276
|
+
// realmKey: realm.key,
|
|
1277
|
+
// placement: index + 1,
|
|
1278
|
+
// message: `${user.username} won ${rewardWinnerMap[index].toFixed(4)} ZOD in Evolution`,
|
|
1279
|
+
// });
|
|
1280
|
+
// }
|
|
1281
|
+
|
|
1282
|
+
// if (req.data.round.winners[0].address === player.address) {
|
|
1283
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.raw)
|
|
1284
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw = {};
|
|
1285
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.raw.wins)
|
|
1286
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.wins = 0;
|
|
1287
|
+
|
|
1288
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.wins[user.address] += 1;
|
|
1289
|
+
|
|
1290
|
+
// if (!app.games.evolution.global.leaderboard.raw) app.games.evolution.global.leaderboard.raw = {};
|
|
1291
|
+
// if (!app.games.evolution.global.leaderboard.raw.wins) app.games.evolution.global.leaderboard.raw.wins = 0;
|
|
1292
|
+
|
|
1293
|
+
// app.games.evolution.global.leaderboard.raw.wins[user.address] += 1;
|
|
1294
|
+
// }
|
|
1295
|
+
// }
|
|
1296
|
+
// }
|
|
1297
|
+
|
|
1298
|
+
// await app.db.saveUser(user);
|
|
1299
|
+
// }
|
|
1300
|
+
|
|
1301
|
+
// log('Round saved');
|
|
1302
|
+
|
|
1303
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
1304
|
+
// id: req.id,
|
|
1305
|
+
// data: { status: 1 },
|
|
1306
|
+
// });
|
|
1307
|
+
// } catch (e) {
|
|
1308
|
+
// log('Error', e);
|
|
1309
|
+
|
|
1310
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
1311
|
+
// id: req.id,
|
|
1312
|
+
// data: { status: 0, message: e },
|
|
1313
|
+
// });
|
|
1314
|
+
|
|
1315
|
+
// disconnectClient(client);
|
|
1316
|
+
// }
|
|
1317
|
+
// });
|
|
1318
|
+
|
|
1319
|
+
// import type * as Arken from '@arken/node/types';
|
|
1320
|
+
// import { isDebug, log } from '@arken/node/util';
|
|
1321
|
+
// import * as dotenv from 'dotenv';
|
|
1322
|
+
// import { catchExceptions, subProcesses } from '@arken/node/util/process';
|
|
1323
|
+
// import fetch from 'node-fetch';
|
|
1324
|
+
|
|
1325
|
+
// import path from 'path';
|
|
1326
|
+
// import jetpack, { find } from 'fs-jetpack';
|
|
1327
|
+
// import beautify from 'json-beautify';
|
|
1328
|
+
// import { fancyTimeFormat } from '@arken/node/util/time';
|
|
1329
|
+
// import md5 from 'js-md5';
|
|
1330
|
+
// import { getClientSocket } from '@arken/node/util/websocket';
|
|
1331
|
+
// import { isValidRequest, getSignedRequest } from '@arken/node/util/web3';
|
|
1332
|
+
// import getUsername from '@arken/node/legacy/getOldUsername';
|
|
1333
|
+
// import { z } from 'zod';
|
|
1334
|
+
|
|
1335
|
+
// export async function monitorEvolutionRealms(app) {}
|
|
1336
|
+
|
|
1337
|
+
// export const createRouter = (t: any) =>
|
|
1338
|
+
// t.router({
|
|
1339
|
+
// saveRound: t.procedure
|
|
1340
|
+
// .input(
|
|
1341
|
+
// z.object({
|
|
1342
|
+
// shardId: z.string(),
|
|
1343
|
+
// roundId: z.number(),
|
|
1344
|
+
// round: z.any(),
|
|
1345
|
+
// rewardWinnerAmount: z.number(),
|
|
1346
|
+
// lastClients: z.any(),
|
|
1347
|
+
// })
|
|
1348
|
+
// )
|
|
1349
|
+
// .mutation(({ input, ctx }) => {
|
|
1350
|
+
// return { status: 1 };
|
|
1351
|
+
// }),
|
|
1352
|
+
|
|
1353
|
+
// getProfile: t.procedure.input(z.string()).query(({ input, ctx }) => {
|
|
1354
|
+
// return { status: 1, data: {} as Arken.Profile.Types.Profile };
|
|
1355
|
+
// }),
|
|
1356
|
+
|
|
1357
|
+
// unbanClient: t.procedure
|
|
1358
|
+
// .input(z.object({ data: z.object({ target: z.string() }), id: z.string() }))
|
|
1359
|
+
// .mutation(({ input, ctx }) => {
|
|
1360
|
+
// service.unbanClient(ctx.app, input);
|
|
1361
|
+
// }),
|
|
1362
|
+
|
|
1363
|
+
// mod: t.procedure
|
|
1364
|
+
// .input(
|
|
1365
|
+
// z.object({
|
|
1366
|
+
// data: z.object({
|
|
1367
|
+
// body: z.object({ signature: z.object({ address: z.string() }) }),
|
|
1368
|
+
// params: z.object({ method: z.string() }),
|
|
1369
|
+
// }),
|
|
1370
|
+
// })
|
|
1371
|
+
// )
|
|
1372
|
+
// .mutation(({ input, ctx }) => {
|
|
1373
|
+
// service.mod(ctx.app, input);
|
|
1374
|
+
// }),
|
|
1375
|
+
|
|
1376
|
+
// banClient: t.procedure
|
|
1377
|
+
// .input(
|
|
1378
|
+
// z.object({
|
|
1379
|
+
// data: z.object({ target: z.string(), reason: z.string(), until: z.number().optional() }),
|
|
1380
|
+
// id: z.string(),
|
|
1381
|
+
// })
|
|
1382
|
+
// )
|
|
1383
|
+
// .mutation(({ input, ctx }) => {
|
|
1384
|
+
// service.banClient(ctx.app, input);
|
|
1385
|
+
// }),
|
|
1386
|
+
|
|
1387
|
+
// getCharacter: t.procedure
|
|
1388
|
+
// .input(z.object({ data: z.object({ address: z.string() }), id: z.string() }))
|
|
1389
|
+
// .mutation(({ input, ctx }) => {
|
|
1390
|
+
// service.getCharacter(ctx.app, input);
|
|
1391
|
+
// }),
|
|
1392
|
+
|
|
1393
|
+
// saveRound: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
1394
|
+
// service.saveRound(ctx.app, input);
|
|
1395
|
+
// }),
|
|
1396
|
+
|
|
1397
|
+
// Add more procedures as necessary
|
|
1398
|
+
// });
|
|
1399
|
+
|
|
1400
|
+
// Add the router type export if necessary
|
|
1401
|
+
// export type Router = ReturnType<typeof createRouter>;
|
|
1402
|
+
|
|
1403
|
+
// class service {
|
|
1404
|
+
// private characters: Record<string, any> = {};
|
|
1405
|
+
|
|
1406
|
+
// async pingRequest(msg: any) {
|
|
1407
|
+
// log('PingRequest', msg);
|
|
1408
|
+
// }
|
|
1409
|
+
|
|
1410
|
+
// async pongRequest(msg: any) {
|
|
1411
|
+
// log('PongRequest', msg);
|
|
1412
|
+
// }
|
|
1413
|
+
|
|
1414
|
+
// async unbanClient(app: Application, req: { data: { target: string }; id: string }) {
|
|
1415
|
+
// log('unbanClient', req);
|
|
1416
|
+
|
|
1417
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
1418
|
+
// delete user.isBanned;
|
|
1419
|
+
// delete user.bannedReason;
|
|
1420
|
+
// await app.db.saveUser(user);
|
|
1421
|
+
|
|
1422
|
+
// app.db.removeBanList('evolution', req.data.target);
|
|
1423
|
+
// app.db.saveBanList();
|
|
1424
|
+
|
|
1425
|
+
// return { status: 1 };
|
|
1426
|
+
// }
|
|
1427
|
+
|
|
1428
|
+
// async mod(app: Application, req: { data: { body: { signature: { address: string } }; params: { method: string } } }) {
|
|
1429
|
+
// log('mod', req);
|
|
1430
|
+
|
|
1431
|
+
// const user = await app.db.loadUser(req.data.body.signature.address);
|
|
1432
|
+
// app.emitAll.playerAction({
|
|
1433
|
+
// key: 'moderator-action',
|
|
1434
|
+
// createdAt: new Date().getTime() / 1000,
|
|
1435
|
+
// address: user.address,
|
|
1436
|
+
// username: user.username,
|
|
1437
|
+
// method: req.data.params.method,
|
|
1438
|
+
// message: `${user.username} called ${req.data.params.method}`,
|
|
1439
|
+
// });
|
|
1440
|
+
|
|
1441
|
+
// return { status: 1 };
|
|
1442
|
+
// }
|
|
1443
|
+
|
|
1444
|
+
// async banClient(app: Application, req: { data: { target: string; reason: string; until?: number }; id: string }) {
|
|
1445
|
+
// log('banClient', req);
|
|
1446
|
+
|
|
1447
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
1448
|
+
// user.isBanned = true;
|
|
1449
|
+
// user.bannedReason = req.data.reason;
|
|
1450
|
+
// user.banExpireDate = req.data.until || new Date().getTime() + 100 * 365 * 24 * 60 * 60; // 100 years by default
|
|
1451
|
+
|
|
1452
|
+
// await app.db.saveUser(user);
|
|
1453
|
+
|
|
1454
|
+
// app.db.addBanList('evolution', {
|
|
1455
|
+
// address: req.data.target,
|
|
1456
|
+
// reason: req.data.reason,
|
|
1457
|
+
// until: req.data.until,
|
|
1458
|
+
// });
|
|
1459
|
+
// app.db.saveBanList();
|
|
1460
|
+
|
|
1461
|
+
// return { status: 1 };
|
|
1462
|
+
// }
|
|
1463
|
+
|
|
1464
|
+
// async getCharacter(app: Application, req: { data: { address: string }; id: string }) {
|
|
1465
|
+
// log('GetCharacterRequest', req);
|
|
1466
|
+
|
|
1467
|
+
// let character = this.characters[req.data.address];
|
|
1468
|
+
// if (!character) {
|
|
1469
|
+
// character = await this.fetchCharacter(app, req.data.address);
|
|
1470
|
+
// this.characters[req.data.address] = character;
|
|
1471
|
+
// }
|
|
1472
|
+
|
|
1473
|
+
// return { status: 1 };
|
|
1474
|
+
// }
|
|
1475
|
+
|
|
1476
|
+
// private async fetchCharacter(app: Application, address: string) {
|
|
1477
|
+
// // Implement character fetching logic here based on your application's needs
|
|
1478
|
+
// return {};
|
|
1479
|
+
// }
|
|
1480
|
+
|
|
1481
|
+
// async saveRound(app: Application, req: any) {
|
|
1482
|
+
// log('SaveRoundRequest', req);
|
|
1483
|
+
|
|
1484
|
+
// if (!(await isValidRequest(app.web3, req)) && app.db.evolution.modList.includes(req.signature.address)) {
|
|
1485
|
+
// log('Round invalid');
|
|
1486
|
+
// return { status: 0, message: 'Invalid signature' };
|
|
1487
|
+
// return;
|
|
1488
|
+
// }
|
|
1489
|
+
|
|
1490
|
+
// return { status: 1 };
|
|
1491
|
+
// }
|
|
1492
|
+
// }
|
|
1493
|
+
|
|
1494
|
+
// export const evolutionService = new EvolutionService();
|
|
1495
|
+
|
|
1496
|
+
// export const evolutionRouter = t.router({
|
|
1497
|
+
// pingRequest: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
1498
|
+
// evolutionService.pingRequest(input);
|
|
1499
|
+
// }),
|
|
1500
|
+
|
|
1501
|
+
// pongRequest: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
1502
|
+
// evolutionService.pongRequest(input);
|
|
1503
|
+
// }),
|
|
1504
|
+
|
|
1505
|
+
// unbanClient: t.procedure
|
|
1506
|
+
// .input(z.object({ data: z.object({ target: z.string() }), id: z.string() }))
|
|
1507
|
+
// .mutation(({ input, ctx }) => {
|
|
1508
|
+
// evolutionService.unbanClient(ctx.app, input);
|
|
1509
|
+
// }),
|
|
1510
|
+
|
|
1511
|
+
// mod: t.procedure
|
|
1512
|
+
// .input(
|
|
1513
|
+
// z.object({
|
|
1514
|
+
// data: z.object({
|
|
1515
|
+
// body: z.object({ signature: z.object({ address: z.string() }) }),
|
|
1516
|
+
// params: z.object({ method: z.string() }),
|
|
1517
|
+
// }),
|
|
1518
|
+
// })
|
|
1519
|
+
// )
|
|
1520
|
+
// .mutation(({ input, ctx }) => {
|
|
1521
|
+
// evolutionService.mod(ctx.app, input);
|
|
1522
|
+
// }),
|
|
1523
|
+
|
|
1524
|
+
// banClient: t.procedure
|
|
1525
|
+
// .input(
|
|
1526
|
+
// z.object({
|
|
1527
|
+
// data: z.object({ target: z.string(), reason: z.string(), until: z.number().optional() }),
|
|
1528
|
+
// id: z.string(),
|
|
1529
|
+
// })
|
|
1530
|
+
// )
|
|
1531
|
+
// .mutation(({ input, ctx }) => {
|
|
1532
|
+
// evolutionService.banClient(ctx.app, input);
|
|
1533
|
+
// }),
|
|
1534
|
+
|
|
1535
|
+
// getCharacter: t.procedure
|
|
1536
|
+
// .input(z.object({ data: z.object({ address: z.string() }), id: z.string() }))
|
|
1537
|
+
// .mutation(({ input, ctx }) => {
|
|
1538
|
+
// evolutionService.getCharacter(ctx.app, input);
|
|
1539
|
+
// }),
|
|
1540
|
+
|
|
1541
|
+
// saveRound: t.procedure.input(z.any()).mutation(({ input, ctx }) => {
|
|
1542
|
+
// evolutionService.saveRound(ctx.app, input);
|
|
1543
|
+
// }),
|
|
1544
|
+
|
|
1545
|
+
// // Add more procedures as necessary
|
|
1546
|
+
// });
|
|
1547
|
+
|
|
1548
|
+
// // Add the router type export if necessary
|
|
1549
|
+
// export type EvolutionRouter = typeof evolutionRouter;
|
|
1550
|
+
|
|
1551
|
+
// const shortId = require('shortid');
|
|
1552
|
+
|
|
1553
|
+
// let CharacterCache = {};
|
|
1554
|
+
// const ioCallbacks = {};
|
|
1555
|
+
|
|
1556
|
+
// async function rsCall(app, realm, name, data = undefined) {
|
|
1557
|
+
// try {
|
|
1558
|
+
// const id = shortId();
|
|
1559
|
+
// const signature =
|
|
1560
|
+
// data !== undefined && data !== null
|
|
1561
|
+
// ? await getSignedRequest(
|
|
1562
|
+
// app.web3,
|
|
1563
|
+
// app.secrets.find((s) => s.id === 'evolution-signer'),
|
|
1564
|
+
// data
|
|
1565
|
+
// )
|
|
1566
|
+
// : null;
|
|
1567
|
+
|
|
1568
|
+
// return new Promise(async (resolve) => {
|
|
1569
|
+
// ioCallbacks[id] = {};
|
|
1570
|
+
|
|
1571
|
+
// ioCallbacks[id].resolve = resolve;
|
|
1572
|
+
|
|
1573
|
+
// ioCallbacks[id].reqTimeout = setTimeout(function () {
|
|
1574
|
+
// log('Request timeout');
|
|
1575
|
+
// resolve({ status: 0, message: 'Request timeout' });
|
|
1576
|
+
|
|
1577
|
+
// delete ioCallbacks[id];
|
|
1578
|
+
// }, 60 * 1000);
|
|
1579
|
+
|
|
1580
|
+
// if (!realm.client.socket?.connected) {
|
|
1581
|
+
// log('Not connected to realm server: ' + realm.key);
|
|
1582
|
+
// return;
|
|
1583
|
+
// }
|
|
1584
|
+
|
|
1585
|
+
// log('Emit Realm', realm.key, name, { id, data });
|
|
1586
|
+
|
|
1587
|
+
// realm.client.socket.emit(name, { id, signature, data });
|
|
1588
|
+
// });
|
|
1589
|
+
// } catch (e) {
|
|
1590
|
+
// log(e);
|
|
1591
|
+
// }
|
|
1592
|
+
// }
|
|
1593
|
+
|
|
1594
|
+
// function setRealmOffline(realm) {
|
|
1595
|
+
// if (realm.status === 'inactive' || realm.updateMode === 'manual') return;
|
|
1596
|
+
|
|
1597
|
+
// realm.status = 'offline';
|
|
1598
|
+
// realm.playerCount = 0;
|
|
1599
|
+
// realm.speculatorCount = 0;
|
|
1600
|
+
// realm.rewardItemAmount = 0;
|
|
1601
|
+
// realm.rewardWinnerAmount = 0;
|
|
1602
|
+
// }
|
|
1603
|
+
|
|
1604
|
+
// async function setRealmConfig(app, realm) {
|
|
1605
|
+
// const configRes = (await rsCall(app, app.games.evolution.realms[realm.key], 'SetConfigRequest', {
|
|
1606
|
+
// config: { ...app.db.evolution.config, roundId: realm.roundId },
|
|
1607
|
+
// })) as any;
|
|
1608
|
+
|
|
1609
|
+
// if (configRes.status !== 1) {
|
|
1610
|
+
// setRealmOffline(realm);
|
|
1611
|
+
// return;
|
|
1612
|
+
// }
|
|
1613
|
+
// }
|
|
1614
|
+
|
|
1615
|
+
// async function updateRealm(app, realm) {
|
|
1616
|
+
// try {
|
|
1617
|
+
// realm.games = [];
|
|
1618
|
+
|
|
1619
|
+
// const infoRes = (await rsCall(app, app.games.evolution.realms[realm.key], 'InfoRequest', { config: {} })) as any; // roundId: realm.roundId
|
|
1620
|
+
|
|
1621
|
+
// if (!infoRes || infoRes.status !== 1) {
|
|
1622
|
+
// setRealmOffline(realm);
|
|
1623
|
+
// return;
|
|
1624
|
+
// }
|
|
1625
|
+
|
|
1626
|
+
// log('infoRes', infoRes.data.games);
|
|
1627
|
+
|
|
1628
|
+
// const { data } = infoRes;
|
|
1629
|
+
|
|
1630
|
+
// realm.playerCount = data.playerCount;
|
|
1631
|
+
// realm.speculatorCount = data.speculatorCount;
|
|
1632
|
+
// realm.version = data.version;
|
|
1633
|
+
|
|
1634
|
+
// realm.games = data.games.map((game) => ({
|
|
1635
|
+
// id: game.id,
|
|
1636
|
+
// playerCount: game.playerCount,
|
|
1637
|
+
// speculatorCount: game.speculatorCount,
|
|
1638
|
+
// version: game.version,
|
|
1639
|
+
// rewardItemAmount: game.rewardItemAmount,
|
|
1640
|
+
// rewardWinnerAmount: game.rewardWinnerAmount,
|
|
1641
|
+
// gameMode: game.gameMode,
|
|
1642
|
+
// connectedPlayers: game.connectedPlayers,
|
|
1643
|
+
// roundId: game.round.id,
|
|
1644
|
+
// roundStartedAt: game.round.startedAt,
|
|
1645
|
+
// timeLeft: ~~(5 * 60 - (new Date().getTime() / 1000 - game.round.startedAt)),
|
|
1646
|
+
// timeLeftText: fancyTimeFormat(5 * 60 - (new Date().getTime() / 1000 - game.round.startedAt)),
|
|
1647
|
+
// endpoint: (function () {
|
|
1648
|
+
// const url = new URL((process.env.ARKEN_ENV === 'local' ? 'http://' : 'https://') + realm.endpoint);
|
|
1649
|
+
// url.port = game.port;
|
|
1650
|
+
// return url.toString();
|
|
1651
|
+
// })()
|
|
1652
|
+
// .replace('http://', '')
|
|
1653
|
+
// .replace('https://', '')
|
|
1654
|
+
// .replace('/', ''),
|
|
1655
|
+
// }));
|
|
1656
|
+
|
|
1657
|
+
// delete realm.timeLeftFancy;
|
|
1658
|
+
|
|
1659
|
+
// realm.status = 'online';
|
|
1660
|
+
// } catch (e) {
|
|
1661
|
+
// log('Error', e);
|
|
1662
|
+
|
|
1663
|
+
// setRealmOffline(realm);
|
|
1664
|
+
// }
|
|
1665
|
+
|
|
1666
|
+
// // log('Updated server', server)
|
|
1667
|
+
|
|
1668
|
+
// return realm;
|
|
1669
|
+
// }
|
|
1670
|
+
|
|
1671
|
+
// async function updateRealms(app) {
|
|
1672
|
+
// try {
|
|
1673
|
+
// log('Updating Evolution realms');
|
|
1674
|
+
|
|
1675
|
+
// let playerCount = 0;
|
|
1676
|
+
|
|
1677
|
+
// for (const realm of app.db.evolution.realms) {
|
|
1678
|
+
// // if (realm.key.indexOf('ptr') !== -1 || realm.key.indexOf('tournament') !== -1) continue
|
|
1679
|
+
// if (realm.status === 'inactive' || realm.updateMode === 'manual') continue;
|
|
1680
|
+
|
|
1681
|
+
// await updateRealm(app, realm);
|
|
1682
|
+
|
|
1683
|
+
// const hist = jetpack.read(path.resolve(`./db/evolution/${realm.key}/historical.json`), 'json') || {};
|
|
1684
|
+
|
|
1685
|
+
// if (!hist.playerCount) hist.playerCount = [];
|
|
1686
|
+
|
|
1687
|
+
// const oldTime = new Date(hist.playerCount[hist.playerCount.length - 1]?.[0] || 0).getTime();
|
|
1688
|
+
// const newTime = new Date().getTime();
|
|
1689
|
+
// const diff = newTime - oldTime;
|
|
1690
|
+
// if (diff / (1000 * 60 * 60 * 1) > 1) {
|
|
1691
|
+
// hist.playerCount.push([newTime, realm.playerCount]);
|
|
1692
|
+
// }
|
|
1693
|
+
|
|
1694
|
+
// jetpack.write(path.resolve(`./db/evolution/${realm.key}/historical.json`), JSON.stringify(hist), {
|
|
1695
|
+
// atomic: true,
|
|
1696
|
+
// jsonIndent: 0,
|
|
1697
|
+
// });
|
|
1698
|
+
|
|
1699
|
+
// playerCount += realm.playerCount;
|
|
1700
|
+
|
|
1701
|
+
// log(`Realm ${realm.key} updated`, realm);
|
|
1702
|
+
// }
|
|
1703
|
+
|
|
1704
|
+
// app.db.evolution.playerCount = playerCount;
|
|
1705
|
+
|
|
1706
|
+
// for (const server of app.db.evolution.servers) {
|
|
1707
|
+
// if (server.status === 'inactive' || server.updateMode === 'manual') continue;
|
|
1708
|
+
// // if (server.key.indexOf('tournament') !== -1) continue
|
|
1709
|
+
|
|
1710
|
+
// server.status = 'offline';
|
|
1711
|
+
// server.playerCount = 0;
|
|
1712
|
+
// }
|
|
1713
|
+
|
|
1714
|
+
// const evolutionServers = app.db.evolution.realms
|
|
1715
|
+
// .filter((r) => r.status !== 'inactive')
|
|
1716
|
+
// .map((r) =>
|
|
1717
|
+
// r.games.length > 0
|
|
1718
|
+
// ? {
|
|
1719
|
+
// ...(app.db.evolution.servers.find((e) => e.key === r.key) || {}),
|
|
1720
|
+
// ...r.games[0],
|
|
1721
|
+
// key: r.key,
|
|
1722
|
+
// name: r.name,
|
|
1723
|
+
// status: r.status,
|
|
1724
|
+
// regionId: r.regionId,
|
|
1725
|
+
// }
|
|
1726
|
+
// : {}
|
|
1727
|
+
// );
|
|
1728
|
+
|
|
1729
|
+
// for (const evolutionServer of evolutionServers) {
|
|
1730
|
+
// const server = app.db.evolution.servers.find((s) => s.key === evolutionServer.key);
|
|
1731
|
+
|
|
1732
|
+
// if (!server) {
|
|
1733
|
+
// if (evolutionServer.key) {
|
|
1734
|
+
// app.db.evolution.servers.push(evolutionServer);
|
|
1735
|
+
// }
|
|
1736
|
+
// continue;
|
|
1737
|
+
// }
|
|
1738
|
+
|
|
1739
|
+
// if (evolutionServer.status === 'inactive' || evolutionServer.updateMode === 'manual') continue;
|
|
1740
|
+
|
|
1741
|
+
// server.status = evolutionServer.status;
|
|
1742
|
+
// server.version = evolutionServer.version;
|
|
1743
|
+
// server.rewardItemAmount = evolutionServer.rewardItemAmount;
|
|
1744
|
+
// server.rewardWinnerAmount = evolutionServer.rewardWinnerAmount;
|
|
1745
|
+
// server.gameMode = evolutionServer.gameMode;
|
|
1746
|
+
// server.roundId = evolutionServer.roundId;
|
|
1747
|
+
// server.roundStartedAt = evolutionServer.roundStartedAt;
|
|
1748
|
+
// server.roundStartedDate = evolutionServer.roundStartedDate;
|
|
1749
|
+
// server.timeLeft = evolutionServer.timeLeft;
|
|
1750
|
+
// server.timeLeftText = evolutionServer.timeLeftText;
|
|
1751
|
+
// server.playerCount = evolutionServer.playerCount;
|
|
1752
|
+
// server.speculatorCount = evolutionServer.speculatorCount;
|
|
1753
|
+
// server.endpoint = evolutionServer.endpoint;
|
|
1754
|
+
// }
|
|
1755
|
+
|
|
1756
|
+
// jetpack.write(path.resolve('./db/evolution/realms.json'), JSON.stringify(app.db.evolution.realms), {
|
|
1757
|
+
// atomic: true,
|
|
1758
|
+
// jsonIndent: 0,
|
|
1759
|
+
// });
|
|
1760
|
+
|
|
1761
|
+
// // Update old servers file
|
|
1762
|
+
// jetpack.write(path.resolve('./db/evolution/servers.json'), JSON.stringify(app.db.evolution.servers), {
|
|
1763
|
+
// atomic: true,
|
|
1764
|
+
// jsonIndent: 0,
|
|
1765
|
+
// });
|
|
1766
|
+
|
|
1767
|
+
// log('Realm and server info generated');
|
|
1768
|
+
|
|
1769
|
+
// // Update overall historics
|
|
1770
|
+
// const hist = jetpack.read(path.resolve(`./db/evolution/historical.json`), 'json') || {};
|
|
1771
|
+
|
|
1772
|
+
// if (!hist.playerCount) hist.playerCount = [];
|
|
1773
|
+
|
|
1774
|
+
// const oldTime = new Date(hist.playerCount[hist.playerCount.length - 1]?.[0] || 0).getTime();
|
|
1775
|
+
// const newTime = new Date().getTime();
|
|
1776
|
+
// const diff = newTime - oldTime;
|
|
1777
|
+
// if (diff / (1000 * 60 * 60 * 1) > 1) {
|
|
1778
|
+
// hist.playerCount.push([newTime, playerCount]);
|
|
1779
|
+
// }
|
|
1780
|
+
|
|
1781
|
+
// jetpack.write(path.resolve(`./db/evolution/historical.json`), JSON.stringify(hist), {
|
|
1782
|
+
// atomic: true,
|
|
1783
|
+
// jsonIndent: 0,
|
|
1784
|
+
// });
|
|
1785
|
+
// } catch (e) {
|
|
1786
|
+
// log('Error', e);
|
|
1787
|
+
// }
|
|
1788
|
+
// }
|
|
1789
|
+
|
|
1790
|
+
// function cleanupClient(client) {
|
|
1791
|
+
// log('Cleaning up', client.key);
|
|
1792
|
+
|
|
1793
|
+
// client.socket?.close();
|
|
1794
|
+
// client.isConnected = false;
|
|
1795
|
+
// client.isConnecting = false;
|
|
1796
|
+
// client.isAuthed = false;
|
|
1797
|
+
|
|
1798
|
+
// clearTimeout(client.timeout);
|
|
1799
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
1800
|
+
// clearTimeout(client.pingerTimeout);
|
|
1801
|
+
// }
|
|
1802
|
+
|
|
1803
|
+
// function disconnectClient(client) {
|
|
1804
|
+
// log('Disconnecting client', client.key);
|
|
1805
|
+
|
|
1806
|
+
// cleanupClient(client);
|
|
1807
|
+
// }
|
|
1808
|
+
|
|
1809
|
+
// async function getCharacter(app, address) {
|
|
1810
|
+
// const equipment = await app.barracks.getPlayerEquipment(app, address);
|
|
1811
|
+
// const meta = await app.barracks.getMetaFromEquipment(app, equipment);
|
|
1812
|
+
|
|
1813
|
+
// // if (address === '0x1a367CA7bD311F279F1dfAfF1e60c4d797Faa6eb') {
|
|
1814
|
+
// // meta[1030] = 100
|
|
1815
|
+
// // }
|
|
1816
|
+
|
|
1817
|
+
// let error;
|
|
1818
|
+
// if (meta[1030] > 100) error = `Problem with EvolutionMovementSpeedIncrease: ${address} ${meta[1030]}`;
|
|
1819
|
+
// if (meta[1102] > 100) error = `Problem with DeathPenaltyAvoid: ${address} ${meta[1102]}`;
|
|
1820
|
+
// if (meta[1104] > 100) error = `Problem with EnergyDecayDecrease: ${address} ${meta[1104]}`;
|
|
1821
|
+
// if (meta[1105] > 100) error = `Problem with EnergyDecayIncrease: ${address} ${meta[1105]}`;
|
|
1822
|
+
// if (meta[1150] > 100) error = `Problem with WinRewardsIncrease: ${address} ${meta[1150]}`;
|
|
1823
|
+
// if (meta[1160] > 100) error = `Problem with WinRewardsDecrease: ${address} ${meta[1160]}`;
|
|
1824
|
+
// if (meta[1222] > 100) error = `Problem with IncreaseMovementSpeedOnKill: ${address} ${meta[1222]}`;
|
|
1825
|
+
// if (meta[1223] > 100) error = `Problem with EvolveMovementBurst: ${address} ${meta[1223]}`;
|
|
1826
|
+
// if (meta[1164] > 100) error = `Problem with DoublePickupChance: ${address} ${meta[1164]}`;
|
|
1827
|
+
// if (meta[1219] > 100) error = `Problem with IncreaseHealthOnKill: ${address} ${meta[1219]}`;
|
|
1828
|
+
// if (meta[1117] > 100) error = `Problem with SpriteFuelIncrease: ${address} ${meta[1117]}`;
|
|
1829
|
+
// if (meta[1118] > 100) error = `Problem with SpriteFuelDecrease: ${address} ${meta[1118]}`;
|
|
1830
|
+
|
|
1831
|
+
// if (error) {
|
|
1832
|
+
// log('Error with character gear:', error);
|
|
1833
|
+
// process.exit(6);
|
|
1834
|
+
// }
|
|
1835
|
+
|
|
1836
|
+
// return {
|
|
1837
|
+
// equipment,
|
|
1838
|
+
// meta,
|
|
1839
|
+
// };
|
|
1840
|
+
// }
|
|
1841
|
+
|
|
1842
|
+
// const runes = [
|
|
1843
|
+
// 'el',
|
|
1844
|
+
// 'eld',
|
|
1845
|
+
// 'tir',
|
|
1846
|
+
// 'nef',
|
|
1847
|
+
// 'ith',
|
|
1848
|
+
// 'tal',
|
|
1849
|
+
// 'ral',
|
|
1850
|
+
// 'ort',
|
|
1851
|
+
// 'thul',
|
|
1852
|
+
// 'amn',
|
|
1853
|
+
// 'sol',
|
|
1854
|
+
// 'shael',
|
|
1855
|
+
// 'dol',
|
|
1856
|
+
// 'hel',
|
|
1857
|
+
// 'io',
|
|
1858
|
+
// 'lum',
|
|
1859
|
+
// 'ko',
|
|
1860
|
+
// 'fal',
|
|
1861
|
+
// 'lem',
|
|
1862
|
+
// 'pul',
|
|
1863
|
+
// 'um',
|
|
1864
|
+
// 'mal',
|
|
1865
|
+
// 'ist',
|
|
1866
|
+
// 'gul',
|
|
1867
|
+
// 'vex',
|
|
1868
|
+
// 'ohm',
|
|
1869
|
+
// 'lo',
|
|
1870
|
+
// 'sur',
|
|
1871
|
+
// 'ber',
|
|
1872
|
+
// 'jah',
|
|
1873
|
+
// 'cham',
|
|
1874
|
+
// 'zod',
|
|
1875
|
+
// ];
|
|
1876
|
+
|
|
1877
|
+
// export async function connectRealm(app, realm) {
|
|
1878
|
+
// if (realm.status === 'inactive' || realm.ignore) return;
|
|
1879
|
+
|
|
1880
|
+
// log('Connecting to realm', realm);
|
|
1881
|
+
// const { client } = app.games.evolution.realms[realm.key];
|
|
1882
|
+
|
|
1883
|
+
// if (client.isConnected || client.socket?.connected) {
|
|
1884
|
+
// log(`Realm ${realm.key} already connected, disconnecting`);
|
|
1885
|
+
// cleanupClient(client);
|
|
1886
|
+
// }
|
|
1887
|
+
|
|
1888
|
+
// client.isConnecting = true;
|
|
1889
|
+
// client.socket = getClientSocket((process.env.ARKEN_ENV === 'local' ? 'http://' : 'https://') + realm.endpoint); // TODO: RS should be running things
|
|
1890
|
+
|
|
1891
|
+
// client.socket.on('connect', async () => {
|
|
1892
|
+
// try {
|
|
1893
|
+
// client.isConnected = true;
|
|
1894
|
+
|
|
1895
|
+
// log('Connected: ' + realm.key);
|
|
1896
|
+
|
|
1897
|
+
// const res = (await rsCall(app, app.games.evolution.realms[realm.key], 'AuthRequest', 'myverysexykey')) as any;
|
|
1898
|
+
|
|
1899
|
+
// if (res.status === 1) {
|
|
1900
|
+
// client.isAuthed = true;
|
|
1901
|
+
|
|
1902
|
+
// clearTimeout(client.connectTimeout);
|
|
1903
|
+
|
|
1904
|
+
// await setRealmConfig(app, realm);
|
|
1905
|
+
// await updateRealm(app, realm);
|
|
1906
|
+
// }
|
|
1907
|
+
|
|
1908
|
+
// client.isConnecting = false;
|
|
1909
|
+
|
|
1910
|
+
// const pinger = async () => {
|
|
1911
|
+
// try {
|
|
1912
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
1913
|
+
|
|
1914
|
+
// client.pingReplyTimeout = setTimeout(function () {
|
|
1915
|
+
// log(`Realm ${realm.key} didnt respond in time, disconnecting`);
|
|
1916
|
+
// cleanupClient(client);
|
|
1917
|
+
// }, 70 * 1000);
|
|
1918
|
+
|
|
1919
|
+
// await rsCall(app, app.games.evolution.realms[realm.key], 'PingRequest');
|
|
1920
|
+
|
|
1921
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
1922
|
+
|
|
1923
|
+
// if (!client.isConnected) return;
|
|
1924
|
+
|
|
1925
|
+
// client.pingerTimeout = setTimeout(async () => await pinger(), 15 * 1000);
|
|
1926
|
+
// } catch (e) {
|
|
1927
|
+
// log(e);
|
|
1928
|
+
// }
|
|
1929
|
+
// };
|
|
1930
|
+
|
|
1931
|
+
// clearTimeout(client.pingerTimeout);
|
|
1932
|
+
// clearTimeout(client.pingReplyTimeout);
|
|
1933
|
+
|
|
1934
|
+
// client.pingerTimeout = setTimeout(async () => await pinger(), 15 * 1000);
|
|
1935
|
+
// } catch (e) {
|
|
1936
|
+
// log('Error', e);
|
|
1937
|
+
// log(`Disconnecting ${realm.key} due to error`);
|
|
1938
|
+
// cleanupClient(client);
|
|
1939
|
+
// }
|
|
1940
|
+
// });
|
|
1941
|
+
|
|
1942
|
+
// client.socket.on('disconnect', () => {
|
|
1943
|
+
// log('Disconnected: ' + realm.key);
|
|
1944
|
+
// cleanupClient(client);
|
|
1945
|
+
// });
|
|
1946
|
+
|
|
1947
|
+
// // client.socket.on('banClient', async function (req) {
|
|
1948
|
+
// // console.log(req)
|
|
1949
|
+
// // try {
|
|
1950
|
+
// // log('Ban', realm.key, req)
|
|
1951
|
+
|
|
1952
|
+
// // if (await isValidRequest(app.web3, req) && app.db.evolution.modList.includes(req.signature.address)) {
|
|
1953
|
+
// // app.db.addBanList('evolution', req.data.target)
|
|
1954
|
+
|
|
1955
|
+
// // app.db.saveBanList()
|
|
1956
|
+
|
|
1957
|
+
// // app.realm.emitAll('BanUserRequest', {
|
|
1958
|
+
// // signature: await getSignedRequest(app.web3, app.secrets, md5(JSON.stringify({ target: req.data.target }))),
|
|
1959
|
+
// // data: {
|
|
1960
|
+
// // target: req.data.target
|
|
1961
|
+
// // }
|
|
1962
|
+
// // })
|
|
1963
|
+
|
|
1964
|
+
// // client.socket.emit('BanUserResponse', {
|
|
1965
|
+
// // id: req.id,
|
|
1966
|
+
// // data: { status: 1 }
|
|
1967
|
+
// // })
|
|
1968
|
+
// // } else {
|
|
1969
|
+
// // client.socket.emit('BanUserResponse', {
|
|
1970
|
+
// // id: req.id,
|
|
1971
|
+
// // data: { status: 0, message: 'Invalid signature' }
|
|
1972
|
+
// // })
|
|
1973
|
+
// // }
|
|
1974
|
+
// // } catch (e) {
|
|
1975
|
+
// // log('Error', e)
|
|
1976
|
+
|
|
1977
|
+
// // client.socket.emit('BanUserResponse', {
|
|
1978
|
+
// // id: req.id,
|
|
1979
|
+
// // data: { status: 0, message: e }
|
|
1980
|
+
// // })
|
|
1981
|
+
// // }
|
|
1982
|
+
// // })
|
|
1983
|
+
|
|
1984
|
+
// client.socket.on('PingRequest', function (msg) {
|
|
1985
|
+
// log('PingRequest', realm.key, msg);
|
|
1986
|
+
|
|
1987
|
+
// client.socket.emit('PingResponse');
|
|
1988
|
+
// });
|
|
1989
|
+
|
|
1990
|
+
// client.socket.on('PongRequest', function (msg) {
|
|
1991
|
+
// log('PongRequest', realm.key, msg);
|
|
1992
|
+
|
|
1993
|
+
// client.socket.emit('PongResponse');
|
|
1994
|
+
// });
|
|
1995
|
+
|
|
1996
|
+
// client.socket.on('unbanClient', async function (req) {
|
|
1997
|
+
// try {
|
|
1998
|
+
// log('Ban', realm.key, req);
|
|
1999
|
+
|
|
2000
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
2001
|
+
|
|
2002
|
+
// delete user.isBanned;
|
|
2003
|
+
// delete user.bannedReason;
|
|
2004
|
+
|
|
2005
|
+
// await app.db.saveUser(user);
|
|
2006
|
+
|
|
2007
|
+
// app.db.removeBanList('evolution', req.data.target);
|
|
2008
|
+
// app.db.saveBanList();
|
|
2009
|
+
|
|
2010
|
+
// app.realm.emitAll('UnbanUserRequest', {
|
|
2011
|
+
// data: {
|
|
2012
|
+
// target: req.data.target,
|
|
2013
|
+
// },
|
|
2014
|
+
// });
|
|
2015
|
+
|
|
2016
|
+
// client.socket.emit('UnbanClientResponse', {
|
|
2017
|
+
// id: req.id,
|
|
2018
|
+
// data: { status: 1 },
|
|
2019
|
+
// });
|
|
2020
|
+
// } catch (e) {
|
|
2021
|
+
// log('Error', e);
|
|
2022
|
+
|
|
2023
|
+
// client.socket.emit('UnbanClientResponse', {
|
|
2024
|
+
// id: req.id,
|
|
2025
|
+
// data: { status: 0, message: e },
|
|
2026
|
+
// });
|
|
2027
|
+
// }
|
|
2028
|
+
// });
|
|
2029
|
+
|
|
2030
|
+
// client.socket.on('mod', async function (req) {
|
|
2031
|
+
// try {
|
|
2032
|
+
// log('mod', realm.key, req);
|
|
2033
|
+
|
|
2034
|
+
// const user = await app.db.loadUser(req.data.body.signature.address);
|
|
2035
|
+
|
|
2036
|
+
// app.api.emitAll('playerAction', {
|
|
2037
|
+
// key: 'moderator-action',
|
|
2038
|
+
// createdAt: new Date().getTime() / 1000,
|
|
2039
|
+
// address: user.address,
|
|
2040
|
+
// username: user.username,
|
|
2041
|
+
// method: req.data.params.method,
|
|
2042
|
+
// realmKey: realm.key,
|
|
2043
|
+
// message: `${user.username} called ${req.data.params.method}`,
|
|
2044
|
+
// });
|
|
2045
|
+
|
|
2046
|
+
// client.socket.emit('ModResponse', {
|
|
2047
|
+
// id: req.id,
|
|
2048
|
+
// data: { status: 1 },
|
|
2049
|
+
// });
|
|
2050
|
+
// } catch (e) {
|
|
2051
|
+
// log('Error', e);
|
|
2052
|
+
|
|
2053
|
+
// client.socket.emit('ModResponse', {
|
|
2054
|
+
// id: req.id,
|
|
2055
|
+
// data: { status: 0, message: e },
|
|
2056
|
+
// });
|
|
2057
|
+
// }
|
|
2058
|
+
// });
|
|
2059
|
+
|
|
2060
|
+
// client.socket.on('banClient', async function (req) {
|
|
2061
|
+
// try {
|
|
2062
|
+
// log('banClient', realm.key, req);
|
|
2063
|
+
|
|
2064
|
+
// const user = await app.db.loadUser(req.data.target);
|
|
2065
|
+
|
|
2066
|
+
// user.isBanned = true;
|
|
2067
|
+
// user.bannedReason = req.data.reason;
|
|
2068
|
+
// user.bannedUntil = req.data.until ? parseInt(req.data.until) : new Date().getTime() + 100 * 365 * 24 * 60 * 60; // 100 year ban by default
|
|
2069
|
+
|
|
2070
|
+
// await app.db.saveUser(user);
|
|
2071
|
+
|
|
2072
|
+
// app.db.addBanList('evolution', { address: req.data.target, reason: req.data.reason, until: req.data.until });
|
|
2073
|
+
// app.db.saveBanList();
|
|
2074
|
+
|
|
2075
|
+
// app.realm.emitAll('BanUserRequest', {
|
|
2076
|
+
// data: {
|
|
2077
|
+
// target: req.data.target,
|
|
2078
|
+
// createdAt: new Date().getTime(),
|
|
2079
|
+
// bannedUntil: user.bannedUntil,
|
|
2080
|
+
// bannedReason: user.bannedReason,
|
|
2081
|
+
// },
|
|
2082
|
+
// });
|
|
2083
|
+
|
|
2084
|
+
// client.socket.emit('BanPlayerResponse', {
|
|
2085
|
+
// id: req.id,
|
|
2086
|
+
// data: { status: 1 },
|
|
2087
|
+
// });
|
|
2088
|
+
// } catch (e) {
|
|
2089
|
+
// log('Error', e);
|
|
2090
|
+
|
|
2091
|
+
// client.socket.emit('BanPlayerResponse', {
|
|
2092
|
+
// id: req.id,
|
|
2093
|
+
// data: { status: 0, message: e },
|
|
2094
|
+
// });
|
|
2095
|
+
// }
|
|
2096
|
+
// });
|
|
2097
|
+
|
|
2098
|
+
// client.socket.on('reportClient', function (msg) {
|
|
2099
|
+
// log('reportClient', realm.key, msg);
|
|
2100
|
+
|
|
2101
|
+
// const { currentGamePlayers, currentPlayer, reportedPlayer } = msg;
|
|
2102
|
+
|
|
2103
|
+
// if (currentPlayer.name.indexOf('Guest') !== -1 || currentPlayer.name.indexOf('Unknown') !== -1) return; // No guest reports
|
|
2104
|
+
|
|
2105
|
+
// if (!app.db.evolution.reportList[reportedPlayer.address]) app.db.evolution.reportList[reportedPlayer.address] = [];
|
|
2106
|
+
|
|
2107
|
+
// if (!app.db.evolution.reportList[reportedPlayer.address].includes(currentPlayer.address))
|
|
2108
|
+
// app.db.evolution.reportList[reportedPlayer.address].push(currentPlayer.address);
|
|
2109
|
+
|
|
2110
|
+
// // if (app.db.evolution.reportList[reportedPlayer.address].length >= 6) {
|
|
2111
|
+
// // app.db.evolution.banList.push(reportedPlayer.address)
|
|
2112
|
+
|
|
2113
|
+
// // disconnectPlayer(reportedPlayer)
|
|
2114
|
+
// // // emitDirect(client.sockets[reportedPlayer.id], 'OnBanned', true)
|
|
2115
|
+
// // return
|
|
2116
|
+
// // }
|
|
2117
|
+
|
|
2118
|
+
// // if (currentGamePlayers.length >= 4) {
|
|
2119
|
+
// // const reportsFromCurrentGamePlayers = app.db.evolution.reportList[reportedPlayer.address].filter(function(n) {
|
|
2120
|
+
// // return currentGamePlayers.indexOf(n) !== -1;
|
|
2121
|
+
// // })
|
|
2122
|
+
|
|
2123
|
+
// // if (reportsFromCurrentGamePlayers.length >= currentGamePlayers.length / 3) {
|
|
2124
|
+
// // app.db.evolution.banList.push(reportedPlayer.address)
|
|
2125
|
+
|
|
2126
|
+
// // disconnectPlayer(reportedPlayer)
|
|
2127
|
+
// // // emitDirect(client.sockets[reportedPlayer.id], 'OnBanned', true)
|
|
2128
|
+
// // return
|
|
2129
|
+
// // }
|
|
2130
|
+
// // }
|
|
2131
|
+
|
|
2132
|
+
// // Relay the report to connected realm servers
|
|
2133
|
+
// });
|
|
2134
|
+
|
|
2135
|
+
// client.socket.on('GetCharacterRequest', async function (req) {
|
|
2136
|
+
// log('GetCharacterRequest', req);
|
|
2137
|
+
|
|
2138
|
+
// try {
|
|
2139
|
+
// let character = CharacterCache[req.data.address];
|
|
2140
|
+
|
|
2141
|
+
// if (!character) {
|
|
2142
|
+
// // if (req.data.address === '0x1a367CA7bD311F279F1dfAfF1e60c4d797Faa6eb') {
|
|
2143
|
+
// // meta[1030] = 100
|
|
2144
|
+
// // }
|
|
2145
|
+
|
|
2146
|
+
// // if (req.data.address === '0x6f756AFaC862A2486f4c1C96b46E00A98a70bEA2') {
|
|
2147
|
+
// // meta[1030] = 100
|
|
2148
|
+
// // }
|
|
2149
|
+
|
|
2150
|
+
// character = await getCharacter(app, req.data.address);
|
|
2151
|
+
|
|
2152
|
+
// CharacterCache[req.data.address] = character;
|
|
2153
|
+
// }
|
|
2154
|
+
|
|
2155
|
+
// log('GetCharacterResponse', character);
|
|
2156
|
+
|
|
2157
|
+
// client.socket.emit('GetCharacterResponse', {
|
|
2158
|
+
// id: req.id,
|
|
2159
|
+
// data: { status: 1, character },
|
|
2160
|
+
// });
|
|
2161
|
+
// } catch (e) {
|
|
2162
|
+
// client.socket.emit('GetCharacterResponse', {
|
|
2163
|
+
// id: req.id,
|
|
2164
|
+
// data: { status: 0, message: 'Error' },
|
|
2165
|
+
// });
|
|
2166
|
+
// }
|
|
2167
|
+
// });
|
|
2168
|
+
|
|
2169
|
+
// client.socket.on('SaveRoundRequest', async function (req) {
|
|
2170
|
+
// // Iterate the items found, add to user.evolution.rewards
|
|
2171
|
+
// // Itereate the runes found, add to user.evolution.runes
|
|
2172
|
+
// // Iterate the winners, add to the user.evolution.runes
|
|
2173
|
+
// // Add winning stats to user.evolution
|
|
2174
|
+
// try {
|
|
2175
|
+
// log('SaveRoundRequest', realm.key, req);
|
|
2176
|
+
|
|
2177
|
+
// if (!(await isValidRequest(app.web3, req)) && app.db.evolution.modList.includes(req.signature.address)) {
|
|
2178
|
+
// log('Round invalid');
|
|
2179
|
+
|
|
2180
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
2181
|
+
// id: req.id,
|
|
2182
|
+
// data: { status: 0, message: 'Invalid signature' },
|
|
2183
|
+
// });
|
|
2184
|
+
// return;
|
|
2185
|
+
// }
|
|
2186
|
+
|
|
2187
|
+
// if (!req.data.lastClients) {
|
|
2188
|
+
// log('Round no clients');
|
|
2189
|
+
|
|
2190
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
2191
|
+
// id: req.id,
|
|
2192
|
+
// data: { status: 0, message: 'Error processing' },
|
|
2193
|
+
// });
|
|
2194
|
+
// return;
|
|
2195
|
+
// }
|
|
2196
|
+
|
|
2197
|
+
// if (req.data.round.winners.length === 0) {
|
|
2198
|
+
// realm.roundId += 1;
|
|
2199
|
+
|
|
2200
|
+
// log('Round skipped');
|
|
2201
|
+
|
|
2202
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
2203
|
+
// id: req.id,
|
|
2204
|
+
// data: { status: 1 },
|
|
2205
|
+
// });
|
|
2206
|
+
// return;
|
|
2207
|
+
// }
|
|
2208
|
+
|
|
2209
|
+
// if (req.data.rewardWinnerAmount > app.db.evolution.config.rewardWinnerAmountMax) {
|
|
2210
|
+
// log(req.data.rewardWinnerAmount, app.db.evolution.config.rewardWinnerAmountMax);
|
|
2211
|
+
// throw new Error('Big problem with reward amount');
|
|
2212
|
+
// }
|
|
2213
|
+
|
|
2214
|
+
// let totalLegitPlayers = 0;
|
|
2215
|
+
|
|
2216
|
+
// for (const client of req.data.lastClients) {
|
|
2217
|
+
// if (client.name.indexOf('Guest') !== -1 || client.name.indexOf('Unknown') !== -1) continue;
|
|
2218
|
+
|
|
2219
|
+
// if (
|
|
2220
|
+
// (client.powerups > 100 && client.kills > 1) ||
|
|
2221
|
+
// (client.evolves > 20 && client.powerups > 200) ||
|
|
2222
|
+
// (client.rewards > 3 && client.powerups > 200) ||
|
|
2223
|
+
// client.evolves > 100 ||
|
|
2224
|
+
// client.points > 1000
|
|
2225
|
+
// ) {
|
|
2226
|
+
// totalLegitPlayers += 1;
|
|
2227
|
+
// }
|
|
2228
|
+
// }
|
|
2229
|
+
|
|
2230
|
+
// if (totalLegitPlayers === 0) {
|
|
2231
|
+
// totalLegitPlayers = 1;
|
|
2232
|
+
// }
|
|
2233
|
+
|
|
2234
|
+
// if (req.data.rewardWinnerAmount > app.db.evolution.config.rewardWinnerAmountPerLegitPlayer * totalLegitPlayers) {
|
|
2235
|
+
// log(
|
|
2236
|
+
// req.data.rewardWinnerAmount,
|
|
2237
|
+
// app.db.evolution.config.rewardWinnerAmountPerLegitPlayer,
|
|
2238
|
+
// totalLegitPlayers,
|
|
2239
|
+
// req.data.lastClients.length,
|
|
2240
|
+
// JSON.stringify(req.data.lastClients)
|
|
2241
|
+
// );
|
|
2242
|
+
// throw new Error('Big problem with reward amount 2');
|
|
2243
|
+
// }
|
|
2244
|
+
|
|
2245
|
+
// if (req.data.roundId > realm.roundId) {
|
|
2246
|
+
// realm.roundId = req.data.roundId;
|
|
2247
|
+
// } else if (req.data.roundId < realm.roundId) {
|
|
2248
|
+
// const err = `Round id too low (realm.roundId = ${realm.roundId})`;
|
|
2249
|
+
|
|
2250
|
+
// log(err);
|
|
2251
|
+
|
|
2252
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
2253
|
+
// id: req.id,
|
|
2254
|
+
// data: { status: 0, message: err },
|
|
2255
|
+
// });
|
|
2256
|
+
|
|
2257
|
+
// await setRealmConfig(app, realm);
|
|
2258
|
+
|
|
2259
|
+
// return;
|
|
2260
|
+
// } else {
|
|
2261
|
+
// realm.roundId += 1;
|
|
2262
|
+
// }
|
|
2263
|
+
|
|
2264
|
+
// // if (req.data.roundId > realm.roundId) {
|
|
2265
|
+
// // client.socket.emit('SaveRoundResponse', {
|
|
2266
|
+
// // id: req.id,
|
|
2267
|
+
// // data: { status: 0, message: 'Invalid round id' }
|
|
2268
|
+
// // })
|
|
2269
|
+
// // return
|
|
2270
|
+
// // }
|
|
2271
|
+
|
|
2272
|
+
// const rewardWinnerMap = {
|
|
2273
|
+
// 0: Math.round(req.data.rewardWinnerAmount * 1 * 1000) / 1000,
|
|
2274
|
+
// 1: Math.round(req.data.rewardWinnerAmount * 0.25 * 1000) / 1000,
|
|
2275
|
+
// 2: Math.round(req.data.rewardWinnerAmount * 0.15 * 1000) / 1000,
|
|
2276
|
+
// 3: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
2277
|
+
// 4: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
2278
|
+
// 5: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
2279
|
+
// 6: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
2280
|
+
// 7: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
2281
|
+
// 8: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
2282
|
+
// 9: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
2283
|
+
// };
|
|
2284
|
+
|
|
2285
|
+
// // const users = []
|
|
2286
|
+
|
|
2287
|
+
// // Iterate the winners, determine the winning amounts, validate, save to user rewards
|
|
2288
|
+
// // Iterate all players and save their log / stats
|
|
2289
|
+
|
|
2290
|
+
// const removeDupes2 = (list) => {
|
|
2291
|
+
// const seen = {};
|
|
2292
|
+
// return list.filter(function (item) {
|
|
2293
|
+
// // console.log(item)
|
|
2294
|
+
// const k1 = item.address;
|
|
2295
|
+
// const exists = seen.hasOwnProperty(k1);
|
|
2296
|
+
|
|
2297
|
+
// if (!exists) {
|
|
2298
|
+
// seen[k1] = true;
|
|
2299
|
+
// }
|
|
2300
|
+
|
|
2301
|
+
// return !exists;
|
|
2302
|
+
// });
|
|
2303
|
+
// };
|
|
2304
|
+
|
|
2305
|
+
// req.data.round.players = removeDupes2(req.data.round.players); // [...new Set(req.data.round.players.map(obj => obj.key)) ] //
|
|
2306
|
+
|
|
2307
|
+
// const winners = req.data.round.winners.slice(0, 10);
|
|
2308
|
+
|
|
2309
|
+
// const rewardTweaks = {};
|
|
2310
|
+
|
|
2311
|
+
// for (const winner of winners) {
|
|
2312
|
+
// let character = CharacterCache[winner.address];
|
|
2313
|
+
|
|
2314
|
+
// if (!character) {
|
|
2315
|
+
// console.log('Getting char data');
|
|
2316
|
+
// character = await getCharacter(app, winner.address);
|
|
2317
|
+
// console.log('Got char data');
|
|
2318
|
+
|
|
2319
|
+
// CharacterCache[winner.address] = character;
|
|
2320
|
+
// }
|
|
2321
|
+
|
|
2322
|
+
// // if (character?.meta?.[1173] > 0) {
|
|
2323
|
+
// // const portion = 0.05
|
|
2324
|
+
|
|
2325
|
+
// // for (const kill of winner.log.kills) {
|
|
2326
|
+
// // const target = req.data.round.players.filter(p => p.hash === kill)
|
|
2327
|
+
|
|
2328
|
+
// // if (target?.address) {
|
|
2329
|
+
// // if (!rewardTweaks[target.address]) rewardTweaks[target.address] = 0
|
|
2330
|
+
// // if (!rewardTweaks[winner.address]) rewardTweaks[winner.address] = 0
|
|
2331
|
+
|
|
2332
|
+
// // rewardTweaks[target.address] -= portion
|
|
2333
|
+
// // rewardTweaks[winner.address] += portion
|
|
2334
|
+
// // }
|
|
2335
|
+
// // }
|
|
2336
|
+
// // }
|
|
2337
|
+
// }
|
|
2338
|
+
|
|
2339
|
+
// for (const player of req.data.round.players) {
|
|
2340
|
+
// console.log('Loading user');
|
|
2341
|
+
// const user = await app.db.loadUser(player.address);
|
|
2342
|
+
// console.log('Loaded user');
|
|
2343
|
+
// const now = new Date().getTime() / 1000;
|
|
2344
|
+
|
|
2345
|
+
// if (user.lastGamePlayed > now - 4 * 60) continue; // Make sure this player isn't in 2 games or somehow getting double rewards
|
|
2346
|
+
|
|
2347
|
+
// if (typeof user.username === 'object' || !user.username) user.username = await getUsername(user.address);
|
|
2348
|
+
|
|
2349
|
+
// if (!user.username) continue; // Make sure cant earn without a character
|
|
2350
|
+
|
|
2351
|
+
// app.db.setUserActive(user);
|
|
2352
|
+
|
|
2353
|
+
// if (player.killStreak >= 10) {
|
|
2354
|
+
// app.api.emitAll('PlayerAction', {
|
|
2355
|
+
// key: 'evolution1-killstreak',
|
|
2356
|
+
// createdAt: new Date().getTime() / 1000,
|
|
2357
|
+
// address: user.address,
|
|
2358
|
+
// username: user.username,
|
|
2359
|
+
// message: `${user.username} got a ${player.killStreak} killstreak in Evolution`,
|
|
2360
|
+
// });
|
|
2361
|
+
// app.notices.add('evolution1-killstreak', {
|
|
2362
|
+
// key: 'evolution1-killstreak',
|
|
2363
|
+
// address: user.address,
|
|
2364
|
+
// username: user.username,
|
|
2365
|
+
// message: `${user.username} got a ${player.killStreak} killstreak in Evolution`,
|
|
2366
|
+
// });
|
|
2367
|
+
// }
|
|
2368
|
+
|
|
2369
|
+
// for (const pickup of player.pickups) {
|
|
2370
|
+
// if (pickup.type === 'rune') {
|
|
2371
|
+
// // TODO: change to authoritative
|
|
2372
|
+
// if (
|
|
2373
|
+
// pickup.quantity >
|
|
2374
|
+
// req.data.round.players.length * app.db.evolution.config.rewardItemAmountPerLegitPlayer * 2
|
|
2375
|
+
// ) {
|
|
2376
|
+
// log(
|
|
2377
|
+
// pickup.quantity,
|
|
2378
|
+
// app.db.evolution.config.rewardItemAmountPerLegitPlayer,
|
|
2379
|
+
// req.data.round.players.length,
|
|
2380
|
+
// JSON.stringify(req.data.round.players)
|
|
2381
|
+
// );
|
|
2382
|
+
// throw new Error('Big problem with item reward amount');
|
|
2383
|
+
// }
|
|
2384
|
+
|
|
2385
|
+
// if (pickup.quantity > req.data.round.players.length * app.db.evolution.config.rewardItemAmountMax) {
|
|
2386
|
+
// log(pickup.quantity, req.data.round.players.length, app.db.evolution.config.rewardItemAmountMax);
|
|
2387
|
+
// throw new Error('Big problem with item reward amount 2');
|
|
2388
|
+
// }
|
|
2389
|
+
|
|
2390
|
+
// const runeSymbol = pickup.rewardItemName.toLowerCase();
|
|
2391
|
+
|
|
2392
|
+
// if (!runes.includes(runeSymbol)) {
|
|
2393
|
+
// continue;
|
|
2394
|
+
// }
|
|
2395
|
+
|
|
2396
|
+
// if (!user.rewards.runes[runeSymbol] || user.rewards.runes[runeSymbol] < 0.000000001) {
|
|
2397
|
+
// user.rewards.runes[runeSymbol] = 0;
|
|
2398
|
+
// }
|
|
2399
|
+
|
|
2400
|
+
// user.rewards.runes[runeSymbol] += pickup.quantity;
|
|
2401
|
+
|
|
2402
|
+
// if (!user.lifetimeRewards.runes[runeSymbol] || user.lifetimeRewards.runes[runeSymbol] < 0.000000001) {
|
|
2403
|
+
// user.lifetimeRewards.runes[runeSymbol] = 0;
|
|
2404
|
+
// }
|
|
2405
|
+
|
|
2406
|
+
// user.lifetimeRewards.runes[runeSymbol] += pickup.quantity;
|
|
2407
|
+
|
|
2408
|
+
// app.db.evolution.config.itemRewards.runes[runeSymbol.toLowerCase()] -= pickup.quantity;
|
|
2409
|
+
|
|
2410
|
+
// app.db.oracle.outflow.evolutionRewards.tokens.week[runeSymbol.toLowerCase()] += pickup.quantity;
|
|
2411
|
+
// } else {
|
|
2412
|
+
// user.rewards.items[pickup.id] = {
|
|
2413
|
+
// name: pickup.name,
|
|
2414
|
+
// rarity: pickup.rarity,
|
|
2415
|
+
// quantity: pickup.quantity,
|
|
2416
|
+
// };
|
|
2417
|
+
|
|
2418
|
+
// user.lifetimeRewards.items[pickup.id] = {
|
|
2419
|
+
// name: pickup.name,
|
|
2420
|
+
// rarity: pickup.rarity,
|
|
2421
|
+
// quantity: pickup.quantity,
|
|
2422
|
+
// };
|
|
2423
|
+
// }
|
|
2424
|
+
|
|
2425
|
+
// // user.rewardTracking.push(req.tracking)
|
|
2426
|
+
// }
|
|
2427
|
+
|
|
2428
|
+
// user.lastGamePlayed = now;
|
|
2429
|
+
|
|
2430
|
+
// if (!user.evolution.hashes) user.evolution.hashes = [];
|
|
2431
|
+
// if (!user.evolution.hashes.includes(player.hash)) user.evolution.hashes.push(player.hash);
|
|
2432
|
+
|
|
2433
|
+
// user.evolution.hashes = user.evolution.hashes.filter(function (item, pos) {
|
|
2434
|
+
// return user.evolution.hashes.indexOf(item) === pos;
|
|
2435
|
+
// });
|
|
2436
|
+
|
|
2437
|
+
// // users.push(user)
|
|
2438
|
+
|
|
2439
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.names)
|
|
2440
|
+
// app.games.evolution.realms[realm.key].leaderboard.names = {};
|
|
2441
|
+
|
|
2442
|
+
// app.games.evolution.realms[realm.key].leaderboard.names[user.address] = user.username;
|
|
2443
|
+
|
|
2444
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.raw.points[user.address]) {
|
|
2445
|
+
// // 'orbs', 'revenges', 'rounds', 'wins', 'timeSpent', 'winRatio', 'killDeathRatio', 'roundPointRatio', 'averageLatency'
|
|
2446
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.monetary[user.address] = 0;
|
|
2447
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.wins[user.address] = 0;
|
|
2448
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rounds[user.address] = 0;
|
|
2449
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.kills[user.address] = 0;
|
|
2450
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.points[user.address] = 0;
|
|
2451
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.deaths[user.address] = 0;
|
|
2452
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.powerups[user.address] = 0;
|
|
2453
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.evolves[user.address] = 0;
|
|
2454
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rewards[user.address] = 0;
|
|
2455
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.pickups[user.address] = 0;
|
|
2456
|
+
// }
|
|
2457
|
+
|
|
2458
|
+
// // Update leaderboard stats
|
|
2459
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rounds[user.address] += 1;
|
|
2460
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.kills[user.address] += player.kills;
|
|
2461
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.points[user.address] += player.points;
|
|
2462
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.deaths[user.address] += player.deaths;
|
|
2463
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.powerups[user.address] += player.powerups;
|
|
2464
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.evolves[user.address] += player.evolves;
|
|
2465
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.rewards[user.address] += player.rewards;
|
|
2466
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.pickups[user.address] += player.pickups.length;
|
|
2467
|
+
|
|
2468
|
+
// if (!app.games.evolution.global.leaderboard.names) app.games.evolution.global.leaderboard.names = {};
|
|
2469
|
+
|
|
2470
|
+
// app.games.evolution.global.leaderboard.names[user.address] = user.username;
|
|
2471
|
+
|
|
2472
|
+
// if (!app.games.evolution.global.leaderboard.raw.points[user.address]) {
|
|
2473
|
+
// // 'orbs', 'revenges', 'rounds', 'wins', 'timeSpent', 'winRatio', 'killDeathRatio', 'roundPointRatio', 'averageLatency'
|
|
2474
|
+
// app.games.evolution.global.leaderboard.raw.monetary[user.address] = 0;
|
|
2475
|
+
// app.games.evolution.global.leaderboard.raw.wins[user.address] = 0;
|
|
2476
|
+
// app.games.evolution.global.leaderboard.raw.rounds[user.address] = 0;
|
|
2477
|
+
// app.games.evolution.global.leaderboard.raw.kills[user.address] = 0;
|
|
2478
|
+
// app.games.evolution.global.leaderboard.raw.points[user.address] = 0;
|
|
2479
|
+
// app.games.evolution.global.leaderboard.raw.deaths[user.address] = 0;
|
|
2480
|
+
// app.games.evolution.global.leaderboard.raw.powerups[user.address] = 0;
|
|
2481
|
+
// app.games.evolution.global.leaderboard.raw.evolves[user.address] = 0;
|
|
2482
|
+
// app.games.evolution.global.leaderboard.raw.rewards[user.address] = 0;
|
|
2483
|
+
// app.games.evolution.global.leaderboard.raw.pickups[user.address] = 0;
|
|
2484
|
+
// }
|
|
2485
|
+
|
|
2486
|
+
// // Update leaderboard stats
|
|
2487
|
+
// app.games.evolution.global.leaderboard.raw.rounds[user.address] += 1;
|
|
2488
|
+
// app.games.evolution.global.leaderboard.raw.kills[user.address] += player.kills;
|
|
2489
|
+
// app.games.evolution.global.leaderboard.raw.points[user.address] += player.points;
|
|
2490
|
+
// app.games.evolution.global.leaderboard.raw.deaths[user.address] += player.deaths;
|
|
2491
|
+
// app.games.evolution.global.leaderboard.raw.powerups[user.address] += player.powerups;
|
|
2492
|
+
// app.games.evolution.global.leaderboard.raw.evolves[user.address] += player.evolves;
|
|
2493
|
+
// app.games.evolution.global.leaderboard.raw.rewards[user.address] += player.rewards;
|
|
2494
|
+
// app.games.evolution.global.leaderboard.raw.pickups[user.address] += player.pickups.length;
|
|
2495
|
+
|
|
2496
|
+
// if (winners.find((winner) => winner.address === player.address)) {
|
|
2497
|
+
// const index = winners.findIndex((winner) => winner.address === player.address);
|
|
2498
|
+
// // const player = req.data.round.winners[index]
|
|
2499
|
+
// // const user = users.find(u => u.address === player.address)
|
|
2500
|
+
|
|
2501
|
+
// // if (!user) continue // He wasn't valid
|
|
2502
|
+
// if (user.username) {
|
|
2503
|
+
// // Make sure cant earn without a character
|
|
2504
|
+
// // if (req.data.round.winners[0].address === player.address) {
|
|
2505
|
+
// let character = CharacterCache[player.address];
|
|
2506
|
+
|
|
2507
|
+
// if (!character) {
|
|
2508
|
+
// console.log('Getting char data');
|
|
2509
|
+
// character = await getCharacter(app, player.address);
|
|
2510
|
+
// console.log('Got char data');
|
|
2511
|
+
|
|
2512
|
+
// CharacterCache[player.address] = character;
|
|
2513
|
+
// }
|
|
2514
|
+
|
|
2515
|
+
// const WinRewardsIncrease = character?.meta?.[1150] || 0;
|
|
2516
|
+
// const WinRewardsDecrease = character?.meta?.[1160] || 0;
|
|
2517
|
+
|
|
2518
|
+
// console.log('bbbb', rewardWinnerMap[index]);
|
|
2519
|
+
// const rewardMultiplier = 1 + (WinRewardsIncrease - WinRewardsDecrease) / 100;
|
|
2520
|
+
|
|
2521
|
+
// if (rewardMultiplier > 2 || rewardMultiplier < 0) {
|
|
2522
|
+
// log(
|
|
2523
|
+
// 'Error with reward multiplier.. bad things happened: ',
|
|
2524
|
+
// rewardMultiplier,
|
|
2525
|
+
// rewardMultiplier,
|
|
2526
|
+
// WinRewardsDecrease
|
|
2527
|
+
// );
|
|
2528
|
+
// process.exit(5);
|
|
2529
|
+
// }
|
|
2530
|
+
|
|
2531
|
+
// rewardWinnerMap[index] *= rewardMultiplier;
|
|
2532
|
+
// console.log('cccc', rewardWinnerMap[index]);
|
|
2533
|
+
// // }
|
|
2534
|
+
|
|
2535
|
+
// if (!user.rewards.runes['zod']) {
|
|
2536
|
+
// user.rewards.runes['zod'] = 0;
|
|
2537
|
+
// }
|
|
2538
|
+
|
|
2539
|
+
// if (user.rewards.runes['zod'] < 0) {
|
|
2540
|
+
// user.rewards.runes['zod'] = 0;
|
|
2541
|
+
// }
|
|
2542
|
+
|
|
2543
|
+
// user.rewards.runes['zod'] += rewardWinnerMap[index];
|
|
2544
|
+
|
|
2545
|
+
// if (!user.lifetimeRewards.runes['zod']) {
|
|
2546
|
+
// user.lifetimeRewards.runes['zod'] = 0;
|
|
2547
|
+
// }
|
|
2548
|
+
|
|
2549
|
+
// user.lifetimeRewards.runes['zod'] += rewardWinnerMap[index];
|
|
2550
|
+
|
|
2551
|
+
// app.db.oracle.outflow.evolutionRewards.tokens.week['zod'] += rewardWinnerMap[index];
|
|
2552
|
+
|
|
2553
|
+
// app.games.evolution.global.leaderboard.raw.monetary[user.address] += rewardWinnerMap[index];
|
|
2554
|
+
|
|
2555
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.monetary[user.address] += rewardWinnerMap[index];
|
|
2556
|
+
|
|
2557
|
+
// app.api.emitAll('PlayerAction', {
|
|
2558
|
+
// key: 'evolution1-winner',
|
|
2559
|
+
// createdAt: new Date().getTime() / 1000,
|
|
2560
|
+
// address: user.address,
|
|
2561
|
+
// username: user.username,
|
|
2562
|
+
// realmKey: realm.key,
|
|
2563
|
+
// placement: index + 1,
|
|
2564
|
+
// message: `${user.username} placed #${index + 1} for ${rewardWinnerMap[index].toFixed(
|
|
2565
|
+
// 4
|
|
2566
|
+
// )} ZOD in Evolution`,
|
|
2567
|
+
// });
|
|
2568
|
+
|
|
2569
|
+
// if (rewardWinnerMap[index] > 0.1) {
|
|
2570
|
+
// app.notices.add('evolution1-winner', {
|
|
2571
|
+
// key: 'evolution1-winner',
|
|
2572
|
+
// address: user.address,
|
|
2573
|
+
// username: user.username,
|
|
2574
|
+
// realmKey: realm.key,
|
|
2575
|
+
// placement: index + 1,
|
|
2576
|
+
// message: `${user.username} won ${rewardWinnerMap[index].toFixed(4)} ZOD in Evolution`,
|
|
2577
|
+
// });
|
|
2578
|
+
// }
|
|
2579
|
+
|
|
2580
|
+
// if (req.data.round.winners[0].address === player.address) {
|
|
2581
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.raw)
|
|
2582
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw = {};
|
|
2583
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard.raw.wins)
|
|
2584
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.wins = 0;
|
|
2585
|
+
|
|
2586
|
+
// app.games.evolution.realms[realm.key].leaderboard.raw.wins[user.address] += 1;
|
|
2587
|
+
|
|
2588
|
+
// if (!app.games.evolution.global.leaderboard.raw) app.games.evolution.global.leaderboard.raw = {};
|
|
2589
|
+
// if (!app.games.evolution.global.leaderboard.raw.wins) app.games.evolution.global.leaderboard.raw.wins = 0;
|
|
2590
|
+
|
|
2591
|
+
// app.games.evolution.global.leaderboard.raw.wins[user.address] += 1;
|
|
2592
|
+
// }
|
|
2593
|
+
// }
|
|
2594
|
+
// }
|
|
2595
|
+
|
|
2596
|
+
// await app.db.saveUser(user);
|
|
2597
|
+
// }
|
|
2598
|
+
|
|
2599
|
+
// log('Round saved');
|
|
2600
|
+
|
|
2601
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
2602
|
+
// id: req.id,
|
|
2603
|
+
// data: { status: 1 },
|
|
2604
|
+
// });
|
|
2605
|
+
// } catch (e) {
|
|
2606
|
+
// log('Error', e);
|
|
2607
|
+
|
|
2608
|
+
// client.socket.emit('SaveRoundResponse', {
|
|
2609
|
+
// id: req.id,
|
|
2610
|
+
// data: { status: 0, message: e },
|
|
2611
|
+
// });
|
|
2612
|
+
|
|
2613
|
+
// disconnectClient(client);
|
|
2614
|
+
// }
|
|
2615
|
+
// });
|
|
2616
|
+
|
|
2617
|
+
// // {
|
|
2618
|
+
// // id: 'vLgqLC_oa',
|
|
2619
|
+
// // signature: {
|
|
2620
|
+
// // address: '0xDfA8f768d82D719DC68E12B199090bDc3691fFc7',
|
|
2621
|
+
// // hash: '0xaa426a32a8f0dae65f160e52d3c0004582e796942894c199255298a05b5f40a473b4257e367e5c285a1eeaf9a8f69b14b8fc273377ab4c79e256962a3434978a1c',
|
|
2622
|
+
// // data: '96a190dbd01b86b08d6feafc6444481b'
|
|
2623
|
+
// // },
|
|
2624
|
+
// // data: {
|
|
2625
|
+
// // id: '7mrEmDnd6',
|
|
2626
|
+
// // data: {
|
|
2627
|
+
// // id: 1,
|
|
2628
|
+
// // startedAt: 1644133312,
|
|
2629
|
+
// // leaders: [Array],
|
|
2630
|
+
// // players: [Array]
|
|
2631
|
+
// // }
|
|
2632
|
+
// // }
|
|
2633
|
+
// // }
|
|
2634
|
+
// // {
|
|
2635
|
+
// // id: 2,
|
|
2636
|
+
// // startedAt: 1644135785,
|
|
2637
|
+
// // leaders: [],
|
|
2638
|
+
// // players: [
|
|
2639
|
+
// // {
|
|
2640
|
+
// // name: 'Sdadasd',
|
|
2641
|
+
// // id: 'ovEbbscHo3D7aWVBAAAD',
|
|
2642
|
+
// // avatar: 0,
|
|
2643
|
+
// // network: 'bsc',
|
|
2644
|
+
// // address: '0x191727d22f2693100acef8e48F8FeaEaa06d30b1',
|
|
2645
|
+
// // device: 'desktop',
|
|
2646
|
+
// // position: [Object],
|
|
2647
|
+
// // target: [Object],
|
|
2648
|
+
// // clientPosition: [Object],
|
|
2649
|
+
// // clientTarget: [Object],
|
|
2650
|
+
// // rotation: null,
|
|
2651
|
+
// // xp: 0,
|
|
2652
|
+
// // latency: 12627.5,
|
|
2653
|
+
// // kills: 0,
|
|
2654
|
+
// // deaths: 0,
|
|
2655
|
+
// // points: 0,
|
|
2656
|
+
// // evolves: 0,
|
|
2657
|
+
// // powerups: 0,
|
|
2658
|
+
// // rewards: 0,
|
|
2659
|
+
// // orbs: 0,
|
|
2660
|
+
// // rewardHistory: [],
|
|
2661
|
+
// // isMod: false,
|
|
2662
|
+
// // isBanned: false,
|
|
2663
|
+
// // isMasterClient: false,
|
|
2664
|
+
// // isDisconnected: true,
|
|
2665
|
+
// // isDead: true,
|
|
2666
|
+
// // isJoining: false,
|
|
2667
|
+
// // isSpectating: false,
|
|
2668
|
+
// // isStuck: false,
|
|
2669
|
+
// // isInvincible: false,
|
|
2670
|
+
// // isPhased: false,
|
|
2671
|
+
// // overrideSpeed: 0.5,
|
|
2672
|
+
// // overrideCameraSize: null,
|
|
2673
|
+
// // cameraSize: 3,
|
|
2674
|
+
// // speed: 0.5,
|
|
2675
|
+
// // joinedAt: 0,
|
|
2676
|
+
// // hash: '',
|
|
2677
|
+
// // lastReportedTime: 1644135787011,
|
|
2678
|
+
// // lastUpdate: 1644135787016,
|
|
2679
|
+
// // gameMode: 'Deathmatch',
|
|
2680
|
+
// // phasedUntil: 1644135814266,
|
|
2681
|
+
// // log: [Object],
|
|
2682
|
+
// // startedRoundAt: 1644135785
|
|
2683
|
+
// // }
|
|
2684
|
+
// // ]
|
|
2685
|
+
// // }
|
|
2686
|
+
|
|
2687
|
+
// client.socket.onAny(function (eventName, res) {
|
|
2688
|
+
// // log('Event All', eventName, res)
|
|
2689
|
+
// if (!res || !res.id) return;
|
|
2690
|
+
// // console.log(eventName, res)
|
|
2691
|
+
// if (ioCallbacks[res.id]) {
|
|
2692
|
+
// log('Callback', eventName, res);
|
|
2693
|
+
|
|
2694
|
+
// clearTimeout(ioCallbacks[res.id].reqTimeout);
|
|
2695
|
+
|
|
2696
|
+
// ioCallbacks[res.id].resolve(res.data);
|
|
2697
|
+
|
|
2698
|
+
// delete ioCallbacks[res.id];
|
|
2699
|
+
// }
|
|
2700
|
+
// });
|
|
2701
|
+
|
|
2702
|
+
// client.socket.connect();
|
|
2703
|
+
|
|
2704
|
+
// client.connectTimeout = setTimeout(function () {
|
|
2705
|
+
// if (!client.isAuthed) {
|
|
2706
|
+
// log(`Couldnt connect/authorize ${realm.key} on ${realm.endpoint}`);
|
|
2707
|
+
// disconnectClient(client);
|
|
2708
|
+
// }
|
|
2709
|
+
// }, 60 * 1000);
|
|
2710
|
+
// }
|
|
2711
|
+
|
|
2712
|
+
// export async function connectRealms(app) {
|
|
2713
|
+
// log('Connecting to Evolution realms');
|
|
2714
|
+
|
|
2715
|
+
// try {
|
|
2716
|
+
// for (const realm of app.db.evolution.realms) {
|
|
2717
|
+
// if (!app.games.evolution.realms[realm.key]) {
|
|
2718
|
+
// app.games.evolution.realms[realm.key] = {};
|
|
2719
|
+
// for (const key in Object.keys(realm)) {
|
|
2720
|
+
// app.games.evolution.realms[realm.key][key] = realm[key];
|
|
2721
|
+
// }
|
|
2722
|
+
// }
|
|
2723
|
+
|
|
2724
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard) app.games.evolution.realms[realm.key].leaderboard = {}
|
|
2725
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw) app.games.evolution.realms[realm.key].leaderboard.raw = {}
|
|
2726
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.wins) app.games.evolution.realms[realm.key].leaderboard.raw.wins = {}
|
|
2727
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.rounds) app.games.evolution.realms[realm.key].leaderboard.raw.rounds = {}
|
|
2728
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.kills) app.games.evolution.realms[realm.key].leaderboard.raw.kills = {}
|
|
2729
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.points) app.games.evolution.realms[realm.key].leaderboard.raw.points = {}
|
|
2730
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.deaths) app.games.evolution.realms[realm.key].leaderboard.raw.deaths = {}
|
|
2731
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.powerups) app.games.evolution.realms[realm.key].leaderboard.raw.powerups = {}
|
|
2732
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.evolves) app.games.evolution.realms[realm.key].leaderboard.raw.evolves = {}
|
|
2733
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.rewards) app.games.evolution.realms[realm.key].leaderboard.raw.rewards = {}
|
|
2734
|
+
// // if (!app.games.evolution.realms[realm.key].leaderboard.raw.pickups) app.games.evolution.realms[realm.key].leaderboard.raw.pickups = {}
|
|
2735
|
+
|
|
2736
|
+
// if (!app.games.evolution.global) {
|
|
2737
|
+
// app.games.evolution.global = {
|
|
2738
|
+
// key: 'global',
|
|
2739
|
+
// };
|
|
2740
|
+
// }
|
|
2741
|
+
|
|
2742
|
+
// if (!app.games.evolution.global.leaderboard) {
|
|
2743
|
+
// app.games.evolution.global.leaderboard = jetpack.read(
|
|
2744
|
+
// path.resolve(`./db/evolution/global/season${app.games.evolution.currentSeason}/leaderboard.json`),
|
|
2745
|
+
// 'json'
|
|
2746
|
+
// ) || {
|
|
2747
|
+
// raw: {
|
|
2748
|
+
// monetary: {},
|
|
2749
|
+
// wins: {},
|
|
2750
|
+
// rounds: {},
|
|
2751
|
+
// rewards: {},
|
|
2752
|
+
// points: {},
|
|
2753
|
+
// kills: {},
|
|
2754
|
+
// deaths: {},
|
|
2755
|
+
// powerups: {},
|
|
2756
|
+
// evolves: {},
|
|
2757
|
+
// pickups: {},
|
|
2758
|
+
// },
|
|
2759
|
+
// names: {},
|
|
2760
|
+
// [app.games.evolution.currentSeason]: {
|
|
2761
|
+
// all: [
|
|
2762
|
+
// {
|
|
2763
|
+
// name: 'Overall',
|
|
2764
|
+
// count: 1000,
|
|
2765
|
+
// data: [],
|
|
2766
|
+
// },
|
|
2767
|
+
// ],
|
|
2768
|
+
// monetary: [
|
|
2769
|
+
// {
|
|
2770
|
+
// name: 'Earnings',
|
|
2771
|
+
// count: 1000,
|
|
2772
|
+
// data: [],
|
|
2773
|
+
// },
|
|
2774
|
+
// ],
|
|
2775
|
+
// wins: [
|
|
2776
|
+
// {
|
|
2777
|
+
// name: 'Wins',
|
|
2778
|
+
// count: 1000,
|
|
2779
|
+
// data: [],
|
|
2780
|
+
// },
|
|
2781
|
+
// ],
|
|
2782
|
+
// rounds: [
|
|
2783
|
+
// {
|
|
2784
|
+
// name: 'Rounds',
|
|
2785
|
+
// count: 1000,
|
|
2786
|
+
// data: [],
|
|
2787
|
+
// },
|
|
2788
|
+
// ],
|
|
2789
|
+
// rewards: [
|
|
2790
|
+
// {
|
|
2791
|
+
// name: 'Rewards',
|
|
2792
|
+
// count: 1000,
|
|
2793
|
+
// data: [],
|
|
2794
|
+
// },
|
|
2795
|
+
// ],
|
|
2796
|
+
// points: [
|
|
2797
|
+
// {
|
|
2798
|
+
// name: 'Points',
|
|
2799
|
+
// count: 1000,
|
|
2800
|
+
// data: [],
|
|
2801
|
+
// },
|
|
2802
|
+
// ],
|
|
2803
|
+
// kills: [
|
|
2804
|
+
// {
|
|
2805
|
+
// name: 'Kills',
|
|
2806
|
+
// count: 1000,
|
|
2807
|
+
// data: [],
|
|
2808
|
+
// },
|
|
2809
|
+
// ],
|
|
2810
|
+
// deaths: [
|
|
2811
|
+
// {
|
|
2812
|
+
// name: 'Deaths',
|
|
2813
|
+
// count: 1000,
|
|
2814
|
+
// data: [],
|
|
2815
|
+
// },
|
|
2816
|
+
// ],
|
|
2817
|
+
// powerups: [
|
|
2818
|
+
// {
|
|
2819
|
+
// name: 'Powerups',
|
|
2820
|
+
// count: 1000,
|
|
2821
|
+
// data: [],
|
|
2822
|
+
// },
|
|
2823
|
+
// ],
|
|
2824
|
+
// evolves: [
|
|
2825
|
+
// {
|
|
2826
|
+
// name: 'Evolves',
|
|
2827
|
+
// count: 1000,
|
|
2828
|
+
// data: [],
|
|
2829
|
+
// },
|
|
2830
|
+
// ],
|
|
2831
|
+
// },
|
|
2832
|
+
// };
|
|
2833
|
+
// }
|
|
2834
|
+
|
|
2835
|
+
// if (!app.games.evolution.realms[realm.key].leaderboard) {
|
|
2836
|
+
// app.games.evolution.realms[realm.key].leaderboard = jetpack.read(
|
|
2837
|
+
// path.resolve(`./db/evolution/${realm.key}/season${app.games.evolution.currentSeason}/leaderboard.json`),
|
|
2838
|
+
// 'json'
|
|
2839
|
+
// ) || {
|
|
2840
|
+
// raw: {
|
|
2841
|
+
// monetary: {},
|
|
2842
|
+
// wins: {},
|
|
2843
|
+
// rounds: {},
|
|
2844
|
+
// rewards: {},
|
|
2845
|
+
// points: {},
|
|
2846
|
+
// kills: {},
|
|
2847
|
+
// deaths: {},
|
|
2848
|
+
// powerups: {},
|
|
2849
|
+
// evolves: {},
|
|
2850
|
+
// pickups: {},
|
|
2851
|
+
// },
|
|
2852
|
+
// names: {},
|
|
2853
|
+
// [app.games.evolution.currentSeason]: {
|
|
2854
|
+
// all: [
|
|
2855
|
+
// {
|
|
2856
|
+
// name: 'Overall',
|
|
2857
|
+
// count: 1000,
|
|
2858
|
+
// data: [],
|
|
2859
|
+
// },
|
|
2860
|
+
// ],
|
|
2861
|
+
// monetary: [
|
|
2862
|
+
// {
|
|
2863
|
+
// name: 'Earnings',
|
|
2864
|
+
// count: 1000,
|
|
2865
|
+
// data: [],
|
|
2866
|
+
// },
|
|
2867
|
+
// ],
|
|
2868
|
+
// wins: [
|
|
2869
|
+
// {
|
|
2870
|
+
// name: 'Wins',
|
|
2871
|
+
// count: 1000,
|
|
2872
|
+
// data: [],
|
|
2873
|
+
// },
|
|
2874
|
+
// ],
|
|
2875
|
+
// rounds: [
|
|
2876
|
+
// {
|
|
2877
|
+
// name: 'Rounds',
|
|
2878
|
+
// count: 1000,
|
|
2879
|
+
// data: [],
|
|
2880
|
+
// },
|
|
2881
|
+
// ],
|
|
2882
|
+
// rewards: [
|
|
2883
|
+
// {
|
|
2884
|
+
// name: 'Rewards',
|
|
2885
|
+
// count: 1000,
|
|
2886
|
+
// data: [],
|
|
2887
|
+
// },
|
|
2888
|
+
// ],
|
|
2889
|
+
// points: [
|
|
2890
|
+
// {
|
|
2891
|
+
// name: 'Points',
|
|
2892
|
+
// count: 1000,
|
|
2893
|
+
// data: [],
|
|
2894
|
+
// },
|
|
2895
|
+
// ],
|
|
2896
|
+
// kills: [
|
|
2897
|
+
// {
|
|
2898
|
+
// name: 'Kills',
|
|
2899
|
+
// count: 1000,
|
|
2900
|
+
// data: [],
|
|
2901
|
+
// },
|
|
2902
|
+
// ],
|
|
2903
|
+
// deaths: [
|
|
2904
|
+
// {
|
|
2905
|
+
// name: 'Deaths',
|
|
2906
|
+
// count: 1000,
|
|
2907
|
+
// data: [],
|
|
2908
|
+
// },
|
|
2909
|
+
// ],
|
|
2910
|
+
// powerups: [
|
|
2911
|
+
// {
|
|
2912
|
+
// name: 'Powerups',
|
|
2913
|
+
// count: 1000,
|
|
2914
|
+
// data: [],
|
|
2915
|
+
// },
|
|
2916
|
+
// ],
|
|
2917
|
+
// evolves: [
|
|
2918
|
+
// {
|
|
2919
|
+
// name: 'Evolves',
|
|
2920
|
+
// count: 1000,
|
|
2921
|
+
// data: [],
|
|
2922
|
+
// },
|
|
2923
|
+
// ],
|
|
2924
|
+
// },
|
|
2925
|
+
// };
|
|
2926
|
+
// }
|
|
2927
|
+
|
|
2928
|
+
// if (!app.games.evolution.realms[realm.key].client) {
|
|
2929
|
+
// app.games.evolution.realms[realm.key].key = realm.key;
|
|
2930
|
+
|
|
2931
|
+
// app.games.evolution.realms[realm.key].client = {
|
|
2932
|
+
// isAuthed: false,
|
|
2933
|
+
// isConnecting: false,
|
|
2934
|
+
// isConnected: false,
|
|
2935
|
+
// socket: null,
|
|
2936
|
+
// connectTimeout: null,
|
|
2937
|
+
// reqTimeout: null,
|
|
2938
|
+
// };
|
|
2939
|
+
// }
|
|
2940
|
+
|
|
2941
|
+
// if (!realm.roundId) {
|
|
2942
|
+
// realm.roundId = 1;
|
|
2943
|
+
// }
|
|
2944
|
+
|
|
2945
|
+
// // if (realm.key.indexOf('ptr') !== -1 || realm.key.indexOf('tournament') !== -1) continue
|
|
2946
|
+
// if (realm.status === 'inactive' || realm.updateMode === 'manual') continue;
|
|
2947
|
+
|
|
2948
|
+
// if (
|
|
2949
|
+
// !app.games.evolution.realms[realm.key].client.isConnected &&
|
|
2950
|
+
// !app.games.evolution.realms[realm.key].client.isConnecting &&
|
|
2951
|
+
// !app.games.evolution.realms[realm.key].client.isAuthed
|
|
2952
|
+
// ) {
|
|
2953
|
+
// await connectRealm(app, realm);
|
|
2954
|
+
// }
|
|
2955
|
+
// }
|
|
2956
|
+
// } catch (e) {
|
|
2957
|
+
// log('Error', e);
|
|
2958
|
+
// }
|
|
2959
|
+
// }
|
|
2960
|
+
|
|
2961
|
+
// export async function emitAll(app, ...args) {
|
|
2962
|
+
// for (const realm of app.db.evolution.realms) {
|
|
2963
|
+
// if (app.games.evolution.realms[realm.key]?.client?.isAuthed) {
|
|
2964
|
+
// console.log('emitAll', realm.key, ...args);
|
|
2965
|
+
// app.games.evolution.realms[realm.key]?.client?.socket.emit(...args);
|
|
2966
|
+
// }
|
|
2967
|
+
// }
|
|
2968
|
+
// }
|
|
2969
|
+
|
|
2970
|
+
// export async function monitorEvolutionRealms(app) {
|
|
2971
|
+
// if (!app.realm) {
|
|
2972
|
+
// app.realm = {};
|
|
2973
|
+
// app.realm.apiAddress = '0x4b64Ff29Ee3B68fF9de11eb1eFA577647f83151C';
|
|
2974
|
+
// app.realm.apiSignature = await getSignedRequest(
|
|
2975
|
+
// app.web3,
|
|
2976
|
+
// app.secrets.find((s) => s.id === 'evolution-signer'),
|
|
2977
|
+
// 'evolution'
|
|
2978
|
+
// );
|
|
2979
|
+
// app.realm.emitAll = emitAll.bind(null, app);
|
|
2980
|
+
// }
|
|
2981
|
+
|
|
2982
|
+
// if (!app.db.evolution.config.rewardWinnerAmountPerLegitPlayerQueued) {
|
|
2983
|
+
// app.db.evolution.config.rewardWinnerAmountPerLegitPlayerQueued =
|
|
2984
|
+
// app.db.evolution.config.rewardWinnerAmountPerLegitPlayer;
|
|
2985
|
+
// }
|
|
2986
|
+
|
|
2987
|
+
// if (!app.db.evolution.config.rewardWinnerAmountMaxQueued) {
|
|
2988
|
+
// app.db.evolution.config.rewardWinnerAmountMaxQueued = app.db.evolution.config.rewardWinnerAmountMax;
|
|
2989
|
+
// }
|
|
2990
|
+
|
|
2991
|
+
// if (!app.db.evolution.config.itemRewards) {
|
|
2992
|
+
// app.db.evolution.config.itemRewards = {
|
|
2993
|
+
// runes: [
|
|
2994
|
+
// {
|
|
2995
|
+
// type: 'rune',
|
|
2996
|
+
// symbol: 'ith',
|
|
2997
|
+
// quantity: 10000,
|
|
2998
|
+
// },
|
|
2999
|
+
// {
|
|
3000
|
+
// type: 'rune',
|
|
3001
|
+
// symbol: 'amn',
|
|
3002
|
+
// quantity: 10000,
|
|
3003
|
+
// },
|
|
3004
|
+
// {
|
|
3005
|
+
// type: 'rune',
|
|
3006
|
+
// symbol: 'ort',
|
|
3007
|
+
// quantity: 10000,
|
|
3008
|
+
// },
|
|
3009
|
+
// {
|
|
3010
|
+
// type: 'rune',
|
|
3011
|
+
// symbol: 'tal',
|
|
3012
|
+
// quantity: 10000,
|
|
3013
|
+
// },
|
|
3014
|
+
// {
|
|
3015
|
+
// type: 'rune',
|
|
3016
|
+
// symbol: 'dol',
|
|
3017
|
+
// quantity: 10000,
|
|
3018
|
+
// },
|
|
3019
|
+
// // {
|
|
3020
|
+
// // "type": "rune",
|
|
3021
|
+
// // "symbol": "sol",
|
|
3022
|
+
// // "quantity": 0
|
|
3023
|
+
// // },
|
|
3024
|
+
// // {
|
|
3025
|
+
// // "type": "rune",
|
|
3026
|
+
// // "symbol": "tir",
|
|
3027
|
+
// // "quantity": 0
|
|
3028
|
+
// // },
|
|
3029
|
+
// // {
|
|
3030
|
+
// // "type": "rune",
|
|
3031
|
+
// // "symbol": "nef",
|
|
3032
|
+
// // "quantity": 0
|
|
3033
|
+
// // },
|
|
3034
|
+
// // {
|
|
3035
|
+
// // "type": "rune",
|
|
3036
|
+
// // "symbol": "hel",
|
|
3037
|
+
// // "quantity": 10000
|
|
3038
|
+
// // },
|
|
3039
|
+
// // {
|
|
3040
|
+
// // "type": "rune",
|
|
3041
|
+
// // "symbol": "ral",
|
|
3042
|
+
// // "quantity": 0
|
|
3043
|
+
// // },
|
|
3044
|
+
// // {
|
|
3045
|
+
// // "type": "rune",
|
|
3046
|
+
// // "symbol": "thul",
|
|
3047
|
+
// // "quantity": 0
|
|
3048
|
+
// // },
|
|
3049
|
+
// // {
|
|
3050
|
+
// // "type": "rune",
|
|
3051
|
+
// // "symbol": "shael",
|
|
3052
|
+
// // "quantity": 0
|
|
3053
|
+
// // },
|
|
3054
|
+
// // {
|
|
3055
|
+
// // "type": "rune",
|
|
3056
|
+
// // "symbol": "ist",
|
|
3057
|
+
// // "quantity": 10000
|
|
3058
|
+
// // },
|
|
3059
|
+
// // {
|
|
3060
|
+
// // "type": "rune",
|
|
3061
|
+
// // "symbol": "mal",
|
|
3062
|
+
// // "quantity": 10000
|
|
3063
|
+
// // },
|
|
3064
|
+
// // {
|
|
3065
|
+
// // "type": "rune",
|
|
3066
|
+
// // "symbol": "um",
|
|
3067
|
+
// // "quantity": 10000
|
|
3068
|
+
// // },
|
|
3069
|
+
// // {
|
|
3070
|
+
// // "type": "rune",
|
|
3071
|
+
// // "symbol": "pul",
|
|
3072
|
+
// // "quantity": 10000
|
|
3073
|
+
// // },
|
|
3074
|
+
// // {
|
|
3075
|
+
// // "type": "rune",
|
|
3076
|
+
// // "symbol": "lum",
|
|
3077
|
+
// // "quantity": 10000
|
|
3078
|
+
// // },
|
|
3079
|
+
// // {
|
|
3080
|
+
// // "type": "rune",
|
|
3081
|
+
// // "symbol": "zod",
|
|
3082
|
+
// // "quantity": 0
|
|
3083
|
+
// // }
|
|
3084
|
+
// ],
|
|
3085
|
+
// items: [],
|
|
3086
|
+
// };
|
|
3087
|
+
// }
|
|
3088
|
+
|
|
3089
|
+
// if (!app.db.evolution.config.itemRewardsQueued) {
|
|
3090
|
+
// app.db.evolution.config.itemRewardsQueued = app.db.evolution.config.itemRewards;
|
|
3091
|
+
// }
|
|
3092
|
+
|
|
3093
|
+
// await connectRealms(app);
|
|
3094
|
+
// await updateRealms(app);
|
|
3095
|
+
|
|
3096
|
+
// setTimeout(() => monitorEvolutionRealms(app), 30 * 1000);
|
|
3097
|
+
// }
|
|
3098
|
+
|
|
3099
|
+
// setInterval(function () {
|
|
3100
|
+
// log('Clearing character cache...');
|
|
3101
|
+
// CharacterCache = {};
|
|
3102
|
+
// }, 30 * 60 * 1000);
|
|
3103
|
+
|
|
3104
|
+
// dotenv.config();
|
|
3105
|
+
|
|
3106
|
+
// export const router = t.router;
|
|
3107
|
+
// export const procedure = procedure;
|
|
3108
|
+
// export const createCallerFactory = t.createCallerFactory;
|
|
3109
|
+
|
|
3110
|
+
// export class Seer {
|
|
3111
|
+
// constructor() {}
|
|
3112
|
+
|
|
3113
|
+
// characters: Record<string, Character> = {};
|
|
3114
|
+
// db: any;
|
|
3115
|
+
// io: any;
|
|
3116
|
+
// app: any;
|
|
3117
|
+
// realm: any;
|
|
3118
|
+
|
|
3119
|
+
// pingRequest(msg: any) {
|
|
3120
|
+
// log('PingRequest', msg);
|
|
3121
|
+
// this.io.emit('PingResponse');
|
|
3122
|
+
// }
|
|
3123
|
+
|
|
3124
|
+
// pongRequest(msg: any) {
|
|
3125
|
+
// log('PongRequest', msg);
|
|
3126
|
+
// this.io.emit('PongResponse');
|
|
3127
|
+
// }
|
|
3128
|
+
|
|
3129
|
+
// async unbanClient(req: { data: { target: string }; id: string }) {
|
|
3130
|
+
// log('unbanClient', req);
|
|
3131
|
+
|
|
3132
|
+
// const user = await this.db.loadUser(req.data.target);
|
|
3133
|
+
// delete user.isBanned;
|
|
3134
|
+
// delete user.banReason;
|
|
3135
|
+
// await this.db.saveUser(user);
|
|
3136
|
+
|
|
3137
|
+
// this.db.removeBanList('evolution', req.data.target);
|
|
3138
|
+
// this.db.saveBanList();
|
|
3139
|
+
|
|
3140
|
+
// return { target: req.data.target };
|
|
3141
|
+
// }
|
|
3142
|
+
|
|
3143
|
+
// async mod(req: {
|
|
3144
|
+
// data: {
|
|
3145
|
+
// body: { signature: { address: string } };
|
|
3146
|
+
// params: { method: string };
|
|
3147
|
+
// };
|
|
3148
|
+
// }) {
|
|
3149
|
+
// log('mod', req);
|
|
3150
|
+
|
|
3151
|
+
// const user = await this.db.loadUser(req.data.body.signature.address);
|
|
3152
|
+
// emitAll('playerAction', {
|
|
3153
|
+
// key: 'moderator-action',
|
|
3154
|
+
// createdAt: new Date().getTime() / 1000,
|
|
3155
|
+
// address: user.address,
|
|
3156
|
+
// username: user.username,
|
|
3157
|
+
// method: req.data.params.method,
|
|
3158
|
+
// message: `${user.username} called ${req.data.params.method}`,
|
|
3159
|
+
// });
|
|
3160
|
+
|
|
3161
|
+
// return { status: 1 };
|
|
3162
|
+
// }
|
|
3163
|
+
|
|
3164
|
+
// async banClient(req: { data: { target: string; reason: string; until?: number }; id: string }) {
|
|
3165
|
+
// log('banClient', req);
|
|
3166
|
+
|
|
3167
|
+
// const user = await this.db.loadUser(req.data.target);
|
|
3168
|
+
// user.isBanned = true;
|
|
3169
|
+
// user.banReason = req.data.reason;
|
|
3170
|
+
// user.banExpireDate = req.data.until || new Date().getTime() + 100 * 365 * 24 * 60 * 60; // 100 years by default
|
|
3171
|
+
|
|
3172
|
+
// await this.db.saveUser(user);
|
|
3173
|
+
|
|
3174
|
+
// this.db.addBanList('evolution', {
|
|
3175
|
+
// address: req.data.target,
|
|
3176
|
+
// reason: req.data.reason,
|
|
3177
|
+
// until: req.data.until,
|
|
3178
|
+
// });
|
|
3179
|
+
|
|
3180
|
+
// this.db.saveBanList();
|
|
3181
|
+
|
|
3182
|
+
// return {
|
|
3183
|
+
// status: 1,
|
|
3184
|
+
// data: {
|
|
3185
|
+
// target: req.data.target,
|
|
3186
|
+
// createdAt: new Date().getTime(),
|
|
3187
|
+
// banExpireDate: user.banExpireDate,
|
|
3188
|
+
// banReason: user.banReason,
|
|
3189
|
+
// },
|
|
3190
|
+
// };
|
|
3191
|
+
// }
|
|
3192
|
+
|
|
3193
|
+
// reportClient(msg: any) {
|
|
3194
|
+
// log('reportClient', msg);
|
|
3195
|
+
|
|
3196
|
+
// const { currentGamePlayers, currentPlayer, reportedPlayer } = msg;
|
|
3197
|
+
|
|
3198
|
+
// if (currentPlayer.name.includes('Guest') || currentPlayer.name.includes('Unknown')) return; // No guest reports
|
|
3199
|
+
|
|
3200
|
+
// if (!this.db.evolution.reportList[reportedPlayer.address]) {
|
|
3201
|
+
// this.db.evolution.reportList[reportedPlayer.address] = [];
|
|
3202
|
+
// }
|
|
3203
|
+
|
|
3204
|
+
// if (!this.db.evolution.reportList[reportedPlayer.address].includes(currentPlayer.address)) {
|
|
3205
|
+
// this.db.evolution.reportList[reportedPlayer.address].push(currentPlayer.address);
|
|
3206
|
+
// }
|
|
3207
|
+
|
|
3208
|
+
// // Additional logic for handling reports and disconnects can be added here
|
|
3209
|
+
|
|
3210
|
+
// // Relay the report to connected realm servers
|
|
3211
|
+
// }
|
|
3212
|
+
|
|
3213
|
+
// setRealmOffline(realm) {
|
|
3214
|
+
// if (realm.status === 'inactive' || realm.updateMode === 'manual') return;
|
|
3215
|
+
|
|
3216
|
+
// realm.status = 'offline';
|
|
3217
|
+
// realm.playerCount = 0;
|
|
3218
|
+
// realm.speculatorCount = 0;
|
|
3219
|
+
// realm.rewardItemAmount = 0;
|
|
3220
|
+
// realm.rewardWinnerAmount = 0;
|
|
3221
|
+
// }
|
|
3222
|
+
|
|
3223
|
+
// async getCharacter(req: { data: { address: string }; id: string }) {
|
|
3224
|
+
// log('GetCharacterRequest', req);
|
|
3225
|
+
|
|
3226
|
+
// let character = this.characters[req.data.address];
|
|
3227
|
+
// if (!character) {
|
|
3228
|
+
// character = await getCharacter(this.app, req.data.address);
|
|
3229
|
+
// this.characters[req.data.address] = character;
|
|
3230
|
+
// }
|
|
3231
|
+
|
|
3232
|
+
// return { status: 1, character };
|
|
3233
|
+
// }
|
|
3234
|
+
|
|
3235
|
+
// async setRealmConfig(app, realm) {
|
|
3236
|
+
// const configRes = (await rsCall(app, app.games.evolution.realms[realm.key], 'SetConfigRequest', {
|
|
3237
|
+
// config: { ...app.db.evolution.config, roundId: realm.roundId },
|
|
3238
|
+
// })) as any;
|
|
3239
|
+
|
|
3240
|
+
// if (configRes.status !== 1) {
|
|
3241
|
+
// this.setRealmOffline(realm);
|
|
3242
|
+
// return;
|
|
3243
|
+
// }
|
|
3244
|
+
// }
|
|
3245
|
+
|
|
3246
|
+
// async saveRound(req) {
|
|
3247
|
+
// log('SaveRoundRequest', this.realm.key, req);
|
|
3248
|
+
|
|
3249
|
+
// if (!(await isValidRequest(this.app.web3, req)) && this.db.evolution.modList.includes(req.signature.address)) {
|
|
3250
|
+
// log('Round invalid');
|
|
3251
|
+
|
|
3252
|
+
// return { status: 0, message: 'Invalid signature' };
|
|
3253
|
+
// }
|
|
3254
|
+
|
|
3255
|
+
// if (!req.data.lastClients) {
|
|
3256
|
+
// log('Round no clients');
|
|
3257
|
+
|
|
3258
|
+
// return { status: 0, message: 'Error processing' };
|
|
3259
|
+
// }
|
|
3260
|
+
|
|
3261
|
+
// if (req.data.round.winners.length === 0) {
|
|
3262
|
+
// this.realm.roundId += 1;
|
|
3263
|
+
|
|
3264
|
+
// log('Round skipped');
|
|
3265
|
+
|
|
3266
|
+
// return { status: 1 };
|
|
3267
|
+
// }
|
|
3268
|
+
|
|
3269
|
+
// if (req.data.rewardWinnerAmount > this.db.evolution.config.rewardWinnerAmountMax) {
|
|
3270
|
+
// log(req.data.rewardWinnerAmount, this.db.evolution.config.rewardWinnerAmountMax);
|
|
3271
|
+
// throw new Error('Big problem with reward amount');
|
|
3272
|
+
// }
|
|
3273
|
+
|
|
3274
|
+
// let totalLegitPlayers = 0;
|
|
3275
|
+
|
|
3276
|
+
// for (const client of req.data.lastClients) {
|
|
3277
|
+
// if (client.name.includes('Guest') || client.name.includes('Unknown')) continue;
|
|
3278
|
+
|
|
3279
|
+
// if (
|
|
3280
|
+
// (client.powerups > 100 && client.kills > 1) ||
|
|
3281
|
+
// (client.evolves > 20 && client.powerups > 200) ||
|
|
3282
|
+
// (client.rewards > 3 && client.powerups > 200) ||
|
|
3283
|
+
// client.evolves > 100 ||
|
|
3284
|
+
// client.points > 1000
|
|
3285
|
+
// ) {
|
|
3286
|
+
// totalLegitPlayers += 1;
|
|
3287
|
+
// }
|
|
3288
|
+
// }
|
|
3289
|
+
|
|
3290
|
+
// if (totalLegitPlayers === 0) {
|
|
3291
|
+
// totalLegitPlayers = 1;
|
|
3292
|
+
// }
|
|
3293
|
+
|
|
3294
|
+
// if (req.data.rewardWinnerAmount > this.db.evolution.config.rewardWinnerAmountPerLegitPlayer * totalLegitPlayers) {
|
|
3295
|
+
// log(
|
|
3296
|
+
// req.data.rewardWinnerAmount,
|
|
3297
|
+
// this.db.evolution.config.rewardWinnerAmountPerLegitPlayer,
|
|
3298
|
+
// totalLegitPlayers,
|
|
3299
|
+
// req.data.lastClients.length,
|
|
3300
|
+
// JSON.stringify(req.data.lastClients)
|
|
3301
|
+
// );
|
|
3302
|
+
// throw new Error('Big problem with reward amount 2');
|
|
3303
|
+
// }
|
|
3304
|
+
|
|
3305
|
+
// if (req.data.roundId > this.realm.roundId) {
|
|
3306
|
+
// this.realm.roundId = req.data.roundId;
|
|
3307
|
+
// } else if (req.data.roundId < this.realm.roundId) {
|
|
3308
|
+
// const err = `Round id too low (realm.roundId = ${this.realm.roundId})`;
|
|
3309
|
+
|
|
3310
|
+
// log(err);
|
|
3311
|
+
|
|
3312
|
+
// await this.setRealmConfig(this.app, this.realm);
|
|
3313
|
+
|
|
3314
|
+
// return { status: 0, message: err };
|
|
3315
|
+
// } else {
|
|
3316
|
+
// this.realm.roundId += 1;
|
|
3317
|
+
// }
|
|
3318
|
+
|
|
3319
|
+
// const rewardWinnerMap = {
|
|
3320
|
+
// 0: Math.round(req.data.rewardWinnerAmount * 1 * 1000) / 1000,
|
|
3321
|
+
// 1: Math.round(req.data.rewardWinnerAmount * 0.25 * 1000) / 1000,
|
|
3322
|
+
// 2: Math.round(req.data.rewardWinnerAmount * 0.15 * 1000) / 1000,
|
|
3323
|
+
// 3: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
3324
|
+
// 4: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
3325
|
+
// 5: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
3326
|
+
// 6: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
3327
|
+
// 7: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
3328
|
+
// 8: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
3329
|
+
// 9: Math.round(req.data.rewardWinnerAmount * 0.05 * 1000) / 1000,
|
|
3330
|
+
// };
|
|
3331
|
+
|
|
3332
|
+
// const removeDupes2 = (list) => {
|
|
3333
|
+
// const seen = {};
|
|
3334
|
+
// return list.filter((item) => {
|
|
3335
|
+
// const k1 = item.address;
|
|
3336
|
+
// if (seen[k1]) {
|
|
3337
|
+
// return false;
|
|
3338
|
+
// } else {
|
|
3339
|
+
// seen[k1] = true;
|
|
3340
|
+
// return true;
|
|
3341
|
+
// }
|
|
3342
|
+
// });
|
|
3343
|
+
// };
|
|
3344
|
+
|
|
3345
|
+
// req.data.round.players = removeDupes2(req.data.round.players);
|
|
3346
|
+
|
|
3347
|
+
// const winners = req.data.round.winners.slice(0, 10);
|
|
3348
|
+
|
|
3349
|
+
// for (const winner of winners) {
|
|
3350
|
+
// let character = this.characters[winner.address];
|
|
3351
|
+
|
|
3352
|
+
// if (!character) {
|
|
3353
|
+
// character = await this.getCharacter(winner.address);
|
|
3354
|
+
// this.characters[winner.address] = character;
|
|
3355
|
+
// }
|
|
3356
|
+
|
|
3357
|
+
// // Additional reward logic based on character's meta data
|
|
3358
|
+
// }
|
|
3359
|
+
|
|
3360
|
+
// for (const player of req.data.round.players) {
|
|
3361
|
+
// const user = await this.db.loadUser(player.address);
|
|
3362
|
+
// const now = new Date().getTime() / 1000;
|
|
3363
|
+
|
|
3364
|
+
// if (user.lastGamePlayed > now - 4 * 60) continue;
|
|
3365
|
+
|
|
3366
|
+
// if (!user.username) user.username = await this.getUsername(user.address);
|
|
3367
|
+
// if (!user.username) continue;
|
|
3368
|
+
|
|
3369
|
+
// this.db.setUserActive(user);
|
|
3370
|
+
|
|
3371
|
+
// if (player.killStreak >= 10) {
|
|
3372
|
+
// this.api.emitAll('PlayerAction', {
|
|
3373
|
+
// key: 'evolution1-killstreak',
|
|
3374
|
+
// createdAt: new Date().getTime() / 1000,
|
|
3375
|
+
// address: user.address,
|
|
3376
|
+
// username: user.username,
|
|
3377
|
+
// message: `${user.username} got a ${player.killStreak} killstreak in Evolution`,
|
|
3378
|
+
// });
|
|
3379
|
+
// this.notices.add('evolution1-killstreak', {
|
|
3380
|
+
// key: 'evolution1-killstreak',
|
|
3381
|
+
// address: user.address,
|
|
3382
|
+
// username: user.username,
|
|
3383
|
+
// message: `${user.username} got a ${player.killStreak} killstreak in Evolution`,
|
|
3384
|
+
// });
|
|
3385
|
+
// }
|
|
3386
|
+
|
|
3387
|
+
// for (const pickup of player.pickups) {
|
|
3388
|
+
// if (pickup.type === 'rune') {
|
|
3389
|
+
// if (
|
|
3390
|
+
// pickup.quantity >
|
|
3391
|
+
// req.data.round.players.length * this.db.evolution.config.rewardItemAmountPerLegitPlayer * 2
|
|
3392
|
+
// ) {
|
|
3393
|
+
// log(
|
|
3394
|
+
// pickup.quantity,
|
|
3395
|
+
// this.db.evolution.config.rewardItemAmountPerLegitPlayer,
|
|
3396
|
+
// req.data.round.players.length,
|
|
3397
|
+
// JSON.stringify(req.data.round.players)
|
|
3398
|
+
// );
|
|
3399
|
+
// throw new Error('Big problem with item reward amount');
|
|
3400
|
+
// }
|
|
3401
|
+
|
|
3402
|
+
// if (pickup.quantity > req.data.round.players.length * this.db.evolution.config.rewardItemAmountMax) {
|
|
3403
|
+
// log(pickup.quantity, req.data.round.players.length, this.db.evolution.config.rewardItemAmountMax);
|
|
3404
|
+
// throw new Error('Big problem with item reward amount 2');
|
|
3405
|
+
// }
|
|
3406
|
+
|
|
3407
|
+
// const runeSymbol = pickup.rewardItemName.toLowerCase();
|
|
3408
|
+
// if (!runes.includes(runeSymbol)) continue;
|
|
3409
|
+
|
|
3410
|
+
// user.rewards.runes[runeSymbol] = (user.rewards.runes[runeSymbol] || 0) + pickup.quantity;
|
|
3411
|
+
// user.lifetimeRewards.runes[runeSymbol] = (user.lifetimeRewards.runes[runeSymbol] || 0) + pickup.quantity;
|
|
3412
|
+
|
|
3413
|
+
// this.db.evolution.config.itemRewards.runes[runeSymbol.toLowerCase()] -= pickup.quantity;
|
|
3414
|
+
// this.db.oracle.outflow.evolutionRewards.tokens.week[runeSymbol.toLowerCase()] += pickup.quantity;
|
|
3415
|
+
// } else {
|
|
3416
|
+
// user.rewards.items[pickup.id] = {
|
|
3417
|
+
// name: pickup.name,
|
|
3418
|
+
// rarity: pickup.rarity,
|
|
3419
|
+
// quantity: pickup.quantity,
|
|
3420
|
+
// };
|
|
3421
|
+
|
|
3422
|
+
// user.lifetimeRewards.items[pickup.id] = {
|
|
3423
|
+
// name: pickup.name,
|
|
3424
|
+
// rarity: pickup.rarity,
|
|
3425
|
+
// quantity: pickup.quantity,
|
|
3426
|
+
// };
|
|
3427
|
+
// }
|
|
3428
|
+
// }
|
|
3429
|
+
|
|
3430
|
+
// user.lastGamePlayed = now;
|
|
3431
|
+
|
|
3432
|
+
// if (!user.evolution.hashes) user.evolution.hashes = [];
|
|
3433
|
+
// if (!user.evolution.hashes.includes(player.hash)) user.evolution.hashes.push(player.hash);
|
|
3434
|
+
|
|
3435
|
+
// user.evolution.hashes = user.evolution.hashes.filter((item, pos) => user.evolution.hashes.indexOf(item) === pos);
|
|
3436
|
+
|
|
3437
|
+
// if (!this.games.evolution.realms[this.realm.key].leaderboard.names)
|
|
3438
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.names = {};
|
|
3439
|
+
|
|
3440
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.names[user.address] = user.username;
|
|
3441
|
+
|
|
3442
|
+
// if (!this.games.evolution.realms[this.realm.key].leaderboard.raw.points[user.address]) {
|
|
3443
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.monetary[user.address] = 0;
|
|
3444
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.wins[user.address] = 0;
|
|
3445
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.rounds[user.address] = 0;
|
|
3446
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.kills[user.address] = 0;
|
|
3447
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.points[user.address] = 0;
|
|
3448
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.deaths[user.address] = 0;
|
|
3449
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.powerups[user.address] = 0;
|
|
3450
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.evolves[user.address] = 0;
|
|
3451
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.rewards[user.address] = 0;
|
|
3452
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.pickups[user.address] = 0;
|
|
3453
|
+
// }
|
|
3454
|
+
|
|
3455
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.rounds[user.address] += 1;
|
|
3456
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.kills[user.address] += player.kills;
|
|
3457
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.points[user.address] += player.points;
|
|
3458
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.deaths[user.address] += player.deaths;
|
|
3459
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.powerups[user.address] += player.powerups;
|
|
3460
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.evolves[user.address] += player.evolves;
|
|
3461
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.rewards[user.address] += player.rewards;
|
|
3462
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.pickups[user.address] += player.pickups.length;
|
|
3463
|
+
|
|
3464
|
+
// if (!this.games.evolution.global.leaderboard.names) this.games.evolution.global.leaderboard.names = {};
|
|
3465
|
+
|
|
3466
|
+
// this.games.evolution.global.leaderboard.names[user.address] = user.username;
|
|
3467
|
+
|
|
3468
|
+
// if (!this.games.evolution.global.leaderboard.raw.points[user.address]) {
|
|
3469
|
+
// this.games.evolution.global.leaderboard.raw.monetary[user.address] = 0;
|
|
3470
|
+
// this.games.evolution.global.leaderboard.raw.wins[user.address] = 0;
|
|
3471
|
+
// this.games.evolution.global.leaderboard.raw.rounds[user.address] = 0;
|
|
3472
|
+
// this.games.evolution.global.leaderboard.raw.kills[user.address] = 0;
|
|
3473
|
+
// this.games.evolution.global.leaderboard.raw.points[user.address] = 0;
|
|
3474
|
+
// this.games.evolution.global.leaderboard.raw.deaths[user.address] = 0;
|
|
3475
|
+
// this.games.evolution.global.leaderboard.raw.powerups[user.address] = 0;
|
|
3476
|
+
// this.games.evolution.global.leaderboard.raw.evolves[user.address] = 0;
|
|
3477
|
+
// this.games.evolution.global.leaderboard.raw.rewards[user.address] = 0;
|
|
3478
|
+
// this.games.evolution.global.leaderboard.raw.pickups[user.address] = 0;
|
|
3479
|
+
// }
|
|
3480
|
+
|
|
3481
|
+
// this.games.evolution.global.leaderboard.raw.rounds[user.address] += 1;
|
|
3482
|
+
// this.games.evolution.global.leaderboard.raw.kills[user.address] += player.kills;
|
|
3483
|
+
// this.games.evolution.global.leaderboard.raw.points[user.address] += player.points;
|
|
3484
|
+
// this.games.evolution.global.leaderboard.raw.deaths[user.address] += player.deaths;
|
|
3485
|
+
// this.games.evolution.global.leaderboard.raw.powerups[user.address] += player.powerups;
|
|
3486
|
+
// this.games.evolution.global.leaderboard.raw.evolves[user.address] += player.evolves;
|
|
3487
|
+
// this.games.evolution.global.leaderboard.raw.rewards[user.address] += player.rewards;
|
|
3488
|
+
// this.games.evolution.global.leaderboard.raw.pickups[user.address] += player.pickups.length;
|
|
3489
|
+
|
|
3490
|
+
// if (winners.find((winner) => winner.address === player.address)) {
|
|
3491
|
+
// const index = winners.findIndex((winner) => winner.address === player.address);
|
|
3492
|
+
// if (user.username) {
|
|
3493
|
+
// let character = this.characters[player.address];
|
|
3494
|
+
|
|
3495
|
+
// if (!character) {
|
|
3496
|
+
// character = await this.getCharacter(player.address);
|
|
3497
|
+
// this.characters[player.address] = character;
|
|
3498
|
+
// }
|
|
3499
|
+
|
|
3500
|
+
// const WinRewardsIncrease = character?.meta?.[1150] || 0;
|
|
3501
|
+
// const WinRewardsDecrease = character?.meta?.[1160] || 0;
|
|
3502
|
+
|
|
3503
|
+
// const rewardMultiplier = 1 + (WinRewardsIncrease - WinRewardsDecrease) / 100;
|
|
3504
|
+
|
|
3505
|
+
// if (rewardMultiplier > 2 || rewardMultiplier < 0) {
|
|
3506
|
+
// log(
|
|
3507
|
+
// 'Error with reward multiplier.. bad things happened: ',
|
|
3508
|
+
// rewardMultiplier,
|
|
3509
|
+
// rewardMultiplier,
|
|
3510
|
+
// WinRewardsDecrease
|
|
3511
|
+
// );
|
|
3512
|
+
// process.exit(5);
|
|
3513
|
+
// }
|
|
3514
|
+
|
|
3515
|
+
// rewardWinnerMap[index] *= rewardMultiplier;
|
|
3516
|
+
|
|
3517
|
+
// if (!user.rewards.runes['zod']) {
|
|
3518
|
+
// user.rewards.runes['zod'] = 0;
|
|
3519
|
+
// }
|
|
3520
|
+
|
|
3521
|
+
// if (user.rewards.runes['zod'] < 0) {
|
|
3522
|
+
// user.rewards.runes['zod'] = 0;
|
|
3523
|
+
// }
|
|
3524
|
+
|
|
3525
|
+
// user.rewards.runes['zod'] += rewardWinnerMap[index];
|
|
3526
|
+
|
|
3527
|
+
// if (!user.lifetimeRewards.runes['zod']) {
|
|
3528
|
+
// user.lifetimeRewards.runes['zod'] = 0;
|
|
3529
|
+
// }
|
|
3530
|
+
|
|
3531
|
+
// user.lifetimeRewards.runes['zod'] += rewardWinnerMap[index];
|
|
3532
|
+
|
|
3533
|
+
// this.db.oracle.outflow.evolutionRewards.tokens.week['zod'] += rewardWinnerMap[index];
|
|
3534
|
+
|
|
3535
|
+
// this.games.evolution.global.leaderboard.raw.monetary[user.address] += rewardWinnerMap[index];
|
|
3536
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.monetary[user.address] += rewardWinnerMap[index];
|
|
3537
|
+
|
|
3538
|
+
// this.api.emitAll('PlayerAction', {
|
|
3539
|
+
// key: 'evolution1-winner',
|
|
3540
|
+
// createdAt: new Date().getTime() / 1000,
|
|
3541
|
+
// address: user.address,
|
|
3542
|
+
// username: user.username,
|
|
3543
|
+
// realmKey: this.realm.key,
|
|
3544
|
+
// placement: index + 1,
|
|
3545
|
+
// message: `${user.username} placed #${index + 1} for ${rewardWinnerMap[index].toFixed(4)} ZOD in Evolution`,
|
|
3546
|
+
// });
|
|
3547
|
+
|
|
3548
|
+
// if (rewardWinnerMap[index] > 0.1) {
|
|
3549
|
+
// this.notices.add('evolution1-winner', {
|
|
3550
|
+
// key: 'evolution1-winner',
|
|
3551
|
+
// address: user.address,
|
|
3552
|
+
// username: user.username,
|
|
3553
|
+
// realmKey: this.realm.key,
|
|
3554
|
+
// placement: index + 1,
|
|
3555
|
+
// message: `${user.username} won ${rewardWinnerMap[index].toFixed(4)} ZOD in Evolution`,
|
|
3556
|
+
// });
|
|
3557
|
+
// }
|
|
3558
|
+
|
|
3559
|
+
// if (req.data.round.winners[0].address === player.address) {
|
|
3560
|
+
// if (!this.games.evolution.realms[this.realm.key].leaderboard.raw)
|
|
3561
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw = {};
|
|
3562
|
+
// if (!this.games.evolution.realms[this.realm.key].leaderboard.raw.wins)
|
|
3563
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.wins = 0;
|
|
3564
|
+
|
|
3565
|
+
// this.games.evolution.realms[this.realm.key].leaderboard.raw.wins[user.address] += 1;
|
|
3566
|
+
|
|
3567
|
+
// if (!this.games.evolution.global.leaderboard.raw) this.games.evolution.global.leaderboard.raw = {};
|
|
3568
|
+
// if (!this.games.evolution.global.leaderboard.raw.wins) this.games.evolution.global.leaderboard.raw.wins = 0;
|
|
3569
|
+
|
|
3570
|
+
// this.games.evolution.global.leaderboard.raw.wins[user.address] += 1;
|
|
3571
|
+
// }
|
|
3572
|
+
// }
|
|
3573
|
+
// }
|
|
3574
|
+
|
|
3575
|
+
// await this.db.saveUser(user);
|
|
3576
|
+
// }
|
|
3577
|
+
|
|
3578
|
+
// log('Round saved');
|
|
3579
|
+
|
|
3580
|
+
// return { status: 1 };
|
|
3581
|
+
// }
|
|
3582
|
+
// }
|
|
3583
|
+
|
|
3584
|
+
// const seer = new Seer();
|
|
3585
|
+
|
|
3586
|
+
// interface ProcedureContext {}
|
|
3587
|
+
|
|
3588
|
+
// export const createRouter = (
|
|
3589
|
+
// handler: (input: unknown, ctx: ProcedureContext) => Promise<void> | void // Adjust the return type if needed
|
|
3590
|
+
// ) => {
|
|
3591
|
+
// return router({
|
|
3592
|
+
// pingRequest: t.procedure.input(z.any()).mutation(({ input }) => seer.pingRequest(input)),
|
|
3593
|
+
|
|
3594
|
+
// pongRequest: t.procedure.input(z.any()).mutation(({ input }) => seer.pongRequest(input)),
|
|
3595
|
+
|
|
3596
|
+
// unbanClient: t.procedure
|
|
3597
|
+
// .input(z.object({ data: z.object({ target: z.string() }) }))
|
|
3598
|
+
// .mutation(({ input }) => seer.unbanClient(input)),
|
|
3599
|
+
|
|
3600
|
+
// mod: t.procedure
|
|
3601
|
+
// .input(
|
|
3602
|
+
// z.object({
|
|
3603
|
+
// data: z.object({
|
|
3604
|
+
// body: z.object({ signature: z.object({ address: z.string() }) }),
|
|
3605
|
+
// }),
|
|
3606
|
+
// })
|
|
3607
|
+
// )
|
|
3608
|
+
// .mutation(({ input }) => seer.mod(input)),
|
|
3609
|
+
|
|
3610
|
+
// banClient: t.procedure
|
|
3611
|
+
// .input(
|
|
3612
|
+
// z.object({
|
|
3613
|
+
// data: z.object({
|
|
3614
|
+
// target: z.string(),
|
|
3615
|
+
// reason: z.string(),
|
|
3616
|
+
// until: z.number().optional(),
|
|
3617
|
+
// }),
|
|
3618
|
+
// id: z.string(),
|
|
3619
|
+
// })
|
|
3620
|
+
// )
|
|
3621
|
+
// .mutation(({ input }) => seer.banClient(input)),
|
|
3622
|
+
|
|
3623
|
+
// reportClient: t.procedure.input(z.any()).mutation(({ input }) => seer.reportClient(input)),
|
|
3624
|
+
|
|
3625
|
+
// getCharacter: t.procedure
|
|
3626
|
+
// .input(z.object({ data: z.object({ address: z.string() }) }))
|
|
3627
|
+
// .mutation(({ input }) => seer.getCharacter(input)),
|
|
3628
|
+
|
|
3629
|
+
// saveRound: t.procedure
|
|
3630
|
+
// .input(
|
|
3631
|
+
// z.object({
|
|
3632
|
+
// data: z.object({
|
|
3633
|
+
// signature: z.object({ address: z.string() }),
|
|
3634
|
+
// lastClients: z.array(z.any()),
|
|
3635
|
+
// rewardWinnerAmount: z.number(),
|
|
3636
|
+
// round: z.object({
|
|
3637
|
+
// winners: z.array(z.any()),
|
|
3638
|
+
// players: z.array(z.any()),
|
|
3639
|
+
// }),
|
|
3640
|
+
// roundId: z.number(),
|
|
3641
|
+
// }),
|
|
3642
|
+
// })
|
|
3643
|
+
// )
|
|
3644
|
+
// .mutation(({ input }) => seer.saveRound(input)),
|
|
3645
|
+
// });
|
|
3646
|
+
// };
|
|
3647
|
+
|
|
3648
|
+
// export type Router = ReturnType<typeof createRouter>;
|