This repository was archived by the owner on May 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
341 lines (273 loc) · 11.7 KB
/
Copy pathplayer.py
File metadata and controls
341 lines (273 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# -*- coding: utf-8 -*-
import re
import emoji
from twisted.internet import reactor
from buffer import Buffer
import util
import datastore
try:
from discord_webhook import DiscordEmbed, DiscordWebhook
except Exception as e:
pass
class Player(object):
def __init__(self, client, name, team, match, skin, gm, isDev, isJunior, isMod, isMuted):
self.client = client
self.server = client.server
self.match = match
self.skin = skin
self.gameMode = gm
self.isDev = isDev
self.isJunior = int(isJunior)
self.isMod = isMod
self.muted = isMuted
if self.client.account:
if self.client.account["isJunior"] == True:
self.isJunior = 1
self.skin = datastore.validateSkin(self.client.username.upper(), skin)
if self.client.username.lower() in ["terminalkade", "dimension", "casini loogi", "nightcat"]:
self.isDev = True
if self.client.username.lower() in ["wacopyrightinfringio", "pyriel", "nexon", "linkytay"]:
self.isMod = True
if len(self.client.username) != 0:
self.strikes = 0
self.name = ' '.join(emoji.emojize(re.sub(r"[^\x00-\x7F]+", "", emoji.demojize(name)).strip())[:20].split()).upper()
if self.name.lower() in ["terminalarch", "dimension", "casini loogi", "nightcat"] and not self.isDev:
if self.server.blockedWebhook is not None:
embed = DiscordEmbed(title="Developer Impersonation", description="Player **{}** has the name of a developer.".format(self.name), color=0x267B8B)
embed.add_embed_field(name="Player", value=self.name, inline=True)
if self.client.username != "":
embed.add_embed_field(name="Username", value=self.client.username, inline=True)
else:
embed.add_embed_field(name="Username", value="No Username", inline=True)
embed.add_embed_field(name="IP", value=self.client.address, inline=True)
self.server.blockedWebhook.add_embed(embed)
self.server.blockedWebhook.execute()
self.server.blockedWebhook.remove_embed(0)
self.forceRenamed = False
self.team = team
if len(self.team) > 0 and not isDev and util.checkCurse(self.name):
self.name = str()
if len(self.name) == 0:
self.name = self.server.defaultName if self.client.username != "" else self.server.defaultName
self.pendingWorld = None
self.level = int()
self.zone = int()
self.posX = int()
self.posY = int()
self.dead = True
self.win = bool()
self.voted = bool()
self.loaded = bool()
self.lobbier = bool()
self.lastUpdatePkt = None
self.wins = 0
self.deaths = 0
self.kills = 0
self.coins = 0
self.hurryingUp = False
self.trustCount = int()
self.lastX = int()
self.lastXOk = True
self.disconnectMessage = "Disconnected"
self.id = match.addPlayer(self)
def sendJSON(self, j):
self.client.sendJSON(j)
def sendText(self, t):
self.client.sendText(t)
def sendBin(self, code, b):
self.client.sendBin(code, b)
def getSimpleData(self, isDev):
result = {"id": self.id, "name": self.name, "team": self.team, "isDev": self.isDev, "isGuest": len(self.client.username) == 0, "isJunior": self.isJunior, "isMod": self.isMod}
if isDev:
result["username"] = self.client.username
return result
def serializePlayerObject(self):
return Buffer().writeInt16(self.id).writeInt8(self.level).writeInt8(self.zone).writeShor2(self.posX, self.posY).writeInt16(self.skin).writeInt8(self.isDev).writeInt8(self.isJunior).writeInt8(self.isMod).toBytes()
def loadWorld(self, worldName, loadMsg):
self.dead = True
self.loaded = False
self.pendingWorld = worldName
self.sendText(loadMsg)
self.client.startDCTimer(15)
def setStartTimer(self, time):
self.sendJSON({"packets": [
{"time": time, "type": "g13"}
], "type": "s01"})
def onEnterIngame(self):
if not self.dead:
return
self.lobbier = self.match.isLobby
self.match.onPlayerEnter(self)
self.loadWorld(self.match.world, self.match.getLoadMsg())
if (self.server.enableLevelSelectInMultiPrivate or self.team == "") and self.match.private or self.isDev:
self.sendLevelSelect()
def sendLevelSelect(self):
levelList = self.server.getLevelList("game", self.match.levelMode)
levelDicts = [{"shortId":self.server.levels[x]["shortname"], "longId":x} for x in levelList]
levelDicts.sort(key=lambda x: x["shortId"])
self.sendJSON({"type": "gll", "levels": levelDicts})
def onLoadComplete(self):
if self.loaded or self.pendingWorld is None:
return
self.client.stopDCTimer()
self.lobbier = self.match.isLobby
self.level = 0
self.zone = 0
self.posX = 35
self.posY = 3
self.win = False
self.dead = False
self.loaded = True
self.pendingWorld = None
self.lastXOk = True
self.flagTouched = False
self.sendBin(0x02, Buffer().writeInt16(self.id).writeInt16(self.skin).writeInt8(self.isDev).writeInt8(self.isJunior).writeInt8(self.isMod)) # ASSIGN_PID
self.match.onPlayerReady(self)
def handlePkt(self, code, b, pktData):
if code == 0x10: # CREATE_PLAYER_OBJECT
level, zone, pos = b.readInt8(), b.readInt8(), b.readShor2()
self.level = level
self.zone = zone
self.posX = pos[0]
self.posY = pos[1]
self.dead = False
self.client.stopDCTimer()
self.match.broadBin(0x10, self.serializePlayerObject())
elif code == 0x11: # KILL_PLAYER_OBJECT
if self.dead or self.win:
return
self.dead = True
self.client.startDCTimer(60)
self.addDeath()
self.match.broadBin(0x11, Buffer().writeInt16(self.id))
self.addLeaderBoardCoins(-10)
elif code == 0x12: # UPDATE_PLAYER_OBJECT
if self.dead or self.lastUpdatePkt == pktData:
return
level, zone, pos, sprite, reverse = b.readInt8(), b.readInt8(), b.readVec2(), b.readInt8(), b.readBool()
if self.level != level or self.zone != zone:
self.match.onPlayerWarp(self, level, zone)
if (self.level < level):
self.flagTouched = False
self.level = level
self.zone = zone
self.posX = pos[0]
self.posY = pos[1]
tile = self.match.getTile(level,zone,int(self.posX),int(self.posY))
tileDef = (tile>>16)&0xff
extraData = (tile>>24)&0xff
if (tileDef == 160 and extraData == 1 and not self.flagTouched):
self.addLeaderBoardCoins(20)
if (tileDef == 160 and extraData == 2 and not self.flagTouched):
self.addLife()
if (tileDef == 160):
self.flagTouched = True
self.lastUpdatePkt = pktData
if sprite > 5 and self.match.world == "lobby" and zone == 0:
self.client.block(0x1)
return
self.match.broadPlayerUpdate(self, pktData)
elif code == 0x13: # PLAYER_OBJECT_EVENT
if self.dead or self.win:
return
type = b.readInt8()
if self.match.world == "lobby":
self.client.block(0x2)
return
self.match.broadBin(0x13, Buffer().writeInt16(self.id).write(pktData))
elif code == 0x17:
killer = b.readInt16()
#type = b.readInt8()
if self.id == killer:
return
killer = self.match.getPlayer(killer)
if killer is None:
return
killer.addKill()
killer.sendBin(0x17, Buffer().writeInt16(self.id).write(pktData))
killer.addLeaderBoardCoins(30)
self.match.killMessage(self, killer)
elif code == 0x18: # PLAYER_RESULT_REQUEST
if self.dead or self.win:
return
self.win = True
#self.client.startDCTimer(120)
pos = self.match.getWinners()
if pos == 1:
self.addWin()
try:
if pos < 4:
self.match.announceWinMessage(self, pos)
# Maybe this should be asynchronous?
if self.server.discordWebhook is not None and pos == 1 and not self.match.private:
name = self.name
# We already filter players that have a squad so...
if len(self.team) == 0 and not self.isDev and util.checkCurse(self.name):
name = "[ censored ]"
embed = DiscordEmbed(description='**%s** has achieved **#1** victory royale!%s' % (name, " (PVP Mode)" if self.gameMode == 1 else " (Hell mode)" if self.gameMode == 2 else ""), color=0xffff00)
self.server.discordWebhook.add_embed(embed)
self.server.discordWebhook.execute()
self.server.discordWebhook.remove_embed(0)
except:
pass
# Make sure that everyone knows that the player is at the axe
self.match.broadPlayerUpdate(self, self.lastUpdatePkt)
if pos == 1:
self.addLeaderBoardCoins(100)
elif pos == 2:
self.addLeaderBoardCoins(50)
elif pos == 3:
self.addLeaderBoardCoins(25)
self.match.broadBin(0x18, Buffer().writeInt16(self.id).writeInt8(pos).writeInt8(0))
elif code == 0x19:
self.trustCount += 1
if self.trustCount > 8:
self.client.block(0x3)
elif code == 0x20: # OBJECT_EVENT_TRIGGER
if self.dead:
return
self.match.objectEventTrigger(self, b, pktData)
elif code == 0x30: # TILE_EVENT_TRIGGER
if self.dead:
return
self.match.tileEventTrigger(self, b, pktData)
def addCoin(self):
if not self.lobbier:
self.coins += 1
self.sendBin(0x21, Buffer().writeInt8(0))
def addWin(self):
if not self.lobbier:
self.wins += 1
def addDeath(self):
if not self.lobbier:
self.deaths += 1
def addKill(self):
if not self.lobbier:
self.kills += 1
def addLife(self):
if not self.lobbier:
self.sendBin(0x23, Buffer().writeInt8(0))
for i in range(30):
self.sendBin(0x21, Buffer().writeInt8(0))
def ban(self, ban):
if (ban):
if self.client.username == "":
self.client.block(0x4)
else:
self.client.blocked = True
self.client.sendClose()
def rename(self, newName):
self.name = newName
self.forceRenamed = True
def hurryUp(self, time):
if self.hurryingUp:
return
self.hurryingUp = True
self.sendJSON({"type":"ghu", "time": time})
self.client.startDCTimerIndependent(time+30)
def addLeaderBoardCoins(self, coins):
if self.client.username == "":
return
if not self.lobbier:
self.coins += coins
self.sendBin(0x22, Buffer().writeInt32(coins))