-
Notifications
You must be signed in to change notification settings - Fork 3
/
NETWORKING
147 lines (130 loc) · 2.69 KB
/
NETWORKING
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
* Server
** Basic Layout
{
"type": <type-of-request>,
"destination": "server"/"client",
<additional data of request>
}
** Initial connect:
*** To the new connection:
{
"type": "server-status",
"destination": "client",
"host": true/false //If the new connection is host
"map": map
"players": player-array
}
*** To all other clients
{
"type": "new-player",
"destination": "client",
"player": <player-struct>
}
** Connection Lost
*** To all clients:
{
"type": "connection-lost",
"destination": "client",
"reason": <reason>,
"player": <player-struct>
}
** Server-Requests
*** set-username
**** Incoming
{
"type": "set-username",
"destination": "server",
"new-username": <username>
}
**** To all
{
"type": "username-changed",
"destination": "client",
"old-name": <old-name>,
"new-name": <new-name>
}
*** get-available-colors
**** Incoming
{
"type": "get-available-colors",
"destination": "server",
}
**** To requester
{
"type": "available-colors",
"destination": "client",
"request": "get-available-colors",
"available-colors": <array-with-colors>
}
*** choose-color
**** Incoming
{
"type": "choose-color",
"destination": "server",
"chosen-color": <color as string>
}
**** To requester *ON ERROR*
{
"destination": "client",
"type": "error",
"request": <the request which failed>,
"reason": <reason for the error>
}
**** To all clients except requester *ON SUCCESS*
{
"destination": "client",
"type": "color-changed",
"new-color": <new-color>,
"player": <player-struct>,
"available-colors": <array of available colors>
}
*** load-map
**** Incoming
{
"type": "load-map",
"destination": "server",
"map-file": <filename>
}
**** To requester if the map can't be found
{
"type": "map-data",
"destination": "client",
"filename": <filename>
}
The client then sends the send-map-data -request to the server
**** To every client except the requester
{
"type": "map-loaded",
"destination": "client",
"filename": <filename>,
"md5sum": <md5sum of the map-data>, //When base64-*decoded*!
"data": <data of file, base64-encoded>
}
**** On error
{
"destination": "client",
"type": "error",
"request": <the request which failed>,
"reason": <reason for the error>
}
*** get-map
**** Incoming
{
"type": "get-map",
"destination": "server",
}
**** To requester
{
"type": "map-loaded",
"destination": "client",
"filename": <filename>,
"md5sum": <md5sum of the map-data>, //When base64-*decoded*!
"data": <data of file, base64-encoded>
}
**** On error
{
"destination": "client",
"type": "error",
"request": <the request which failed>,
"reason": <reason for the error>
}