-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPacket.py
More file actions
169 lines (117 loc) · 3.44 KB
/
Packet.py
File metadata and controls
169 lines (117 loc) · 3.44 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
import time,string
class Packet(object):
packetID =-1
def __init__(self,iD):
self.packetID==iD
def getID(self, data):
return data[:2]
def readData(self, data):
return data[2:len(data)]
def writeData(self,server):
server.sendDataToAllClients(self.getData())
def writeDataToServer(self,client):
client.sendDataToServer(self.getData())
class Packet00Login(Packet):
def __init__(self,username="",x=0,y=0):
super(Packet00Login,self).__init__(00)
self.username = username
self.x = x
self.y = y
def receivePacket(self,data):
stuff = string.split(data,",")
self.username = stuff[0][2:]
self.x = stuff[1]
self.y = stuff[2]
def getData(self):
return "00" + self.username+','+str(self.x)+','+str(self.y)
def getUsername(self):
return self.username
class Packet01Disconnect(Packet):
def __init__(self,username=""):
super(Packet01Disconnect,self).__init__(01)
self.username = username
def receivePacket(self,data):
stuff = string.split(data,",")
self.username = stuff[0][2:]
def getData(self):
return "01" + self.username
def getUsername(self):
return self.username
class Packet02Move(Packet):
def __init__(self,username="",x=0,y=0,movingDir=0,isSwimming=False,):
super(Packet02Move,self).__init__(02)
self.username = username
self.x=x
self.y=y
self.isSwimming = isSwimming
self.movingDir = movingDir
def receivePacket(self,data):
stuff = string.split(data,",")
self.username = stuff[0][2:]
self.x=stuff[1]
self.y=stuff[2]
self.movingDir = stuff[3]
self.isSwimming = stuff[4]
def getData(self):
return "02" + self.username +','+str(int(self.x))+','+str(int(self.y))+','+str(self.movingDir)+','+str(self.isSwimming)
def getUsername(self):
return self.username
class Packet03AddEntity(Packet):
def __init__(self,idd=0,t="",x=0,y=0):
super(Packet03AddEntity,self).__init__(03)
self.id = idd
self.type = t
self.x=x
self.y=y
def receivePacket(self,data):
stuff = string.split(data,",")
self.id = stuff[0][2:]
self.type=stuff[1]
self.x=stuff[2]
self.y=stuff[3]
def getData(self):
return "03" + str(self.id) +','+self.type+','+str(int(self.x))+','+str(int(self.y))
class Packet04MoveEntity(Packet):
def __init__(self,id=0,x=0,y=0,movingDir=0,isSwimming = False):
super(Packet04MoveEntity,self).__init__(04)
self.id = id
self.x=x
self.y=y
self.movingDir = movingDir
self.isSwimming = isSwimming
def receivePacket(self,data):
stuff = string.split(data,",")
self.id = stuff[0][2:]
self.x=stuff[1]
self.y=stuff[2]
self.movingDir=stuff[3]
self.isSwimming = stuff[4]
def getData(self):
return "04" + str(self.id) +','+str(int(self.x))+','+str(int(self.y))+','+str(self.movingDir)+','+str(self.isSwimming)
class Packet05SendTiles(Packet):
def __init__(self,tiles=0):
super(Packet05SendTiles,self).__init__(05)
self.tiles = tiles
def receivePacket(self,data):
self.tiles = data[2:]
def getData(self):
return "05" + self.getTilesString()
def getTilesString(self):
t = ""
for s in self.tiles:
t+=str(s)
t+=','
return t
class Packet06UpdateTile(Packet):
def __init__(self,tile=0,x=0,y=0):
super(Packet06UpdateTile,self).__init__(06)
self.tile = tile
self.x = x
self.y = y
def receivePacket(self,data):
stuff = string.split(data,",")
self.tile = stuff[0][2:]
self.x=stuff[1]
self.y=stuff[2]
def getData(self):
return "06" +str(self.tile) + ',' + str(self.x) + ',' + str(self.y)