-
Notifications
You must be signed in to change notification settings - Fork 0
/
PROTOCOL
159 lines (106 loc) · 5.4 KB
/
PROTOCOL
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
==== Client States ====
1) Init: When logged out
2) Logged: When logged to the server but not playing
==== Arguments types ====
username: String representing a username uniquely identifying a student. Each student
can only be simultaneously logged once on the server.
challenge: a 52 chars long hex representation of a sha1() hash composed of the actual
password and the salt provided by the server.
msg: A plain string explaining why the nack occured
white,
black,
timers: The number of seconds in the clocks
from,
to: chess positions in algebraid notation (e.g. b4)
promotion: a capital letter indicating the piece type
(R: rook, N: Knight, Q: queen, B: Bishop)
salt: a string generated randomly for each server connections
winner: The color of the winner "white"/"black"
logged: Whether the user is currently logged in (yes/no)
==== Server Commands ====
=== Status: Init ===
command: <auth><login username=".." challenge=".." /></auth>
reply: <auth><ack /> / <nack msg=".." /></auth>
status: Init => Logged
description: challenge is sha1(sha1(password)+salt). salt is transmitted by the server
within the <hello> command
=== Status: Logged ===
command: <auth><logout /></auth>
reply: <auth><ack /> / <nack msg=".." /></auth>
status: Logged => Init
command: <chess username=".."><create timers=".." /></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
comment: The server will then send a <chess username=".."><invite timers=".." /></games> to the player
command: <chess username=".."><inviteaccept /></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
comment: The server will then send a <chess username=".."><inviteaccept /></games> to the host
command: <chess username=".."><invitedecline /></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
comment: The server will then send a <chess username=".."><invitedecline /></games> to the host
command: <chess username=".."><timers /></chess>
out: <chess username=".."><timers white=".." black=".." /></chess>
command: <chess username=".."><move from=".." to=".."/></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
command: <chess username=".."><movepromote from=".." to=".." promotion=".."/></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
command: <chess username=".."><drawask /></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
comment: If a draw can be requested (not enought material for checkmate, 50 moves
rules or 3 similar conditions) the draw will be accepted without asking
the opponent.
command: <chess username=".."><drawaccept /></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
comment: You can only accept a draw immediately after recieving a draw request
command: <chess username=".."><drawdecline /></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
comment: You can only decline a draw immediately after recieving a draw request
command: <chess username=".."><resign /></chess>
reply: <chess username=".."><ack /> / <nack msg=".." /></chess>
==== Replies received from the server ====
=== On connection: ===
<hello salt=".." />
=== When hosting a game: ===
When you host, you'll receive a notification once the opponent accepts or rejects
your invitation, if he accepts, the game automatically starts:
<chess username=".."><inviteaccept /></chess>
or:
<chess username=".."><invitedecline /></chess>
=== Being invited ===
Whenever somebody creates a game with you, you'll receive an invitation looking like:
<chess username=".."><invite timers=".."/></chess>
You need to reply with:
<chess username=".."><inviteaccept /></chess>
or:
<chess username=".."><invitedecline /></chess>
=== When playing a game: ===
You'll receive a notification of the opponents moves and actions:
<chess username=".."><move from=".." to=".."/></chess>
<chess username=".."><movepromote from=".." to=".." promotion=".."/></chess>
<chess username=".."><drawask /></chess>
<chess username=".."><drawdecline /></chess>
On game end:
<chess username=".."><end winner=".." /></chess>
<chess username=".."><draw /></chess>
==== Chatting ====
You can chat when logged or playing.
command: <chat username=".."><msg>..</msg></chat>
reply: <chat username=".."><ack /> / <nack msg=".." /></chat>
Received from server when somebody writes to you:
<chat username=".."><msg>..</msg></chat>
==== GPS ====
Register your current position:
command: <gps><register long=".." lat=".." /></gps>
reply: <gps><ack /> /<nack msg=".." /></gps>
Retrieve others position:
command: <gps><get username=".." /></gps>
reply: <gps><position username=".." long=".." lat=".." logged=".." /></gps>
reply: <gps><position username=".." long="N/A" lat="N/A" logged="no" /></gps>
==== Protocol Extensions ====
You can extend the protocol with your own commands. Simply send
<[maintag] username="[target]">[content]</[maintag]>
and the server will translate it to:
<[maintag] username="[source]">[content]</[maintag]>
and send it to [target]. You will then receive either
<[maintag] username="[target]"><ack /></[maintag]>
or
<[maintag] username="[target]"><nack msg=".." /></[maintag]>