Protocole » History » Version 1
Greg Burri, 07/28/2008 09:26 AM
| 1 | 1 | Greg Burri | h1. Protocole |
|---|---|---|---|
| 2 | |||
| 3 | h2. Introduction |
||
| 4 | |||
| 5 | Ce document a pour but de décrire la communication client-serveur du site euphorik. |
||
| 6 | Les messages échangés sont basés sur le format JSON. |
||
| 7 | Ce document remplace 'protocole2.txt'. |
||
| 8 | |||
| 9 | |||
| 10 | h2. Principes |
||
| 11 | |||
| 12 | h3. Enregistrement: |
||
| 13 | |||
| 14 | * Permet de créer un compte, un cookie est donné en retour. Ce cookie doit être stocké par le client pour pouvoir s'authentifier par la suite. |
||
| 15 | |||
| 16 | |||
| 17 | h3. Authentification: |
||
| 18 | |||
| 19 | * L'authentification (login) se fait soit par un couple <login, mot de passe> soit à l'aide d'un cookie. |
||
| 20 | * Permet de récupérer les données d'un profile |
||
| 21 | |||
| 22 | |||
| 23 | h3. Rafraichissement: |
||
| 24 | |||
| 25 | * Le client envoie une demande au serveur avec l'id du dernier message (via XMLHttpRequest ou un function de JQuery) |
||
| 26 | * Le serveur maintient la connexion bloquée si le client est à jour. |
||
| 27 | * Dès qu'un nouveau message arrive, le serveur débloque la connexion et envoie le ou les messages manquants. |
||
| 28 | |||
| 29 | |||
| 30 | h2. Protocole |
||
| 31 | |||
| 32 | <pre> |
||
| 33 | c : client |
||
| 34 | s : server |
||
| 35 | </pre> |
||
| 36 | Les messages client vers serveur sont envoyés par HTTP-POST. |
||
| 37 | |||
| 38 | A toutes les requêtes le serveur peut répondre une erreur : |
||
| 39 | <pre> |
||
| 40 | <error> |
||
| 41 | { |
||
| 42 | "reply" : "error", |
||
| 43 | |||
| 44 | "error_message" : "blabla" |
||
| 45 | } |
||
| 46 | </pre> |
||
| 47 | |||
| 48 | Message ok générique : |
||
| 49 | <ok> |
||
| 50 | { |
||
| 51 | "reply" : "ok" |
||
| 52 | } |
||
| 53 | |||
| 54 | Entete des messages clients : |
||
| 55 | Si la version du protocole n'est pas similaire du coté serveur la requête est refusée |
||
| 56 | <client_header> |
||
| 57 | { |
||
| 58 | "action" : <action>, |
||
| 59 | "version" : 3 |
||
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | === Enregistrement et authentification === |
||
| 64 | Permet de créer un nouvel utilisateur. |
||
| 65 | "login" et "password" peuvent ne pas être fournis avec un message de type "register", dans ce cas l'utilisateur ne pourra s'authentifier qu'a l'aide de son cookie. |
||
| 66 | Le mot de passe est hashé en md5. |
||
| 67 | |||
| 68 | c -> s |
||
| 69 | { |
||
| 70 | "header" : {action : "register", version : 3}, |
||
| 71 | "login" : "paul", |
||
| 72 | "password" : "IJKJDHHSAD9081238", |
||
| 73 | "profile" : { .. } // voir <profile> |
||
| 74 | } |
||
| 75 | ou |
||
| 76 | { |
||
| 77 | "header" : {action : "authentification", version : 3} |
||
| 78 | "cookie" : "LKJDLAKSJBFLKASN" |
||
| 79 | } |
||
| 80 | ou |
||
| 81 | { |
||
| 82 | "header" : {action : "authentification", version : 3}, |
||
| 83 | "login" : "paul", |
||
| 84 | "password" : "IJKJDHHSAD9081238" |
||
| 85 | } |
||
| 86 | |||
| 87 | s -> c |
||
| 88 | { |
||
| 89 | "reply" : "register" | "authentification", |
||
| 90 | "status" : "auth_registered" | "auth_not_registered", |
||
| 91 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 92 | "id" : 193, |
||
| 93 | "login" : "paul49", |
||
| 94 | "ek_master" : true | false, |
||
| 95 | "profile" : <profile> |
||
| 96 | } |
||
| 97 | |||
| 98 | |||
| 99 | === Logout === |
||
| 100 | c -> s |
||
| 101 | { |
||
| 102 | "header" : {action : "logout", version : 3}, |
||
| 103 | "cookie" : "LKJDLAKSJBFLKASN" |
||
| 104 | } |
||
| 105 | |||
| 106 | |||
| 107 | === Profile === |
||
| 108 | <profile> |
||
| 109 | { |
||
| 110 | "nick" : "Paul", |
||
| 111 | "email" : "paul@pierre.com", |
||
| 112 | "css" : "css/3/euphorik.css", |
||
| 113 | "chat_order" : "chrono" | "reverse", |
||
| 114 | "nick_format" : "nick" | "login" | "nick_login", |
||
| 115 | "view_times" : true | false, |
||
| 116 | "view_tooltips" : true | false, |
||
| 117 | "conversations" : [{"root" : 3, "minimized" : true}, |
||
| 118 | "ostentatious_master" : "invisible" | "light" | "heavy" |
||
| 119 | } |
||
| 120 | |||
| 121 | c -> s |
||
| 122 | { |
||
| 123 | "header" : {action : "set_profile", version : 3}, |
||
| 124 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 125 | "login" : "paul49", |
||
| 126 | "password" : "IJKJDHHSAD9081238", |
||
| 127 | "profile" : <profile> |
||
| 128 | } |
||
| 129 | |||
| 130 | s -> c |
||
| 131 | <ok> |
||
| 132 | ou |
||
| 133 | <error> |
||
| 134 | |||
| 135 | |||
| 136 | === Wait event (page = chat) === |
||
| 137 | Si "last_message_id" est absent alors le client ne possède pas de message. |
||
| 138 | Si "main_page" est absent alors est vaut 1. |
||
| 139 | "cookie" n'est pas obligatoire. |
||
| 140 | |||
| 141 | <message> |
||
| 142 | { |
||
| 143 | "id" : 54, |
||
| 144 | "user_id" : 344, |
||
| 145 | "date" : "Hier 17:26:54", |
||
| 146 | "system" : true | false, |
||
| 147 | "owner" : true | false, |
||
| 148 | "answered" : true | false, |
||
| 149 | "is_a_reply" : true | false, |
||
| 150 | "nick" : "Paul", |
||
| 151 | "login" : "paul_22", |
||
| 152 | "content" : "Salut", |
||
| 153 | "root" : 453, |
||
| 154 | "answer_to" : [ |
||
| 155 | { "id" : 123, "nick" : "Pierre", "login" : "pierre_45" } |
||
| 156 | ], |
||
| 157 | "ek_master" : true | false, |
||
| 158 | "ostentatious_master" : "invisible" | "light" | "heavy", |
||
| 159 | "last_modification" : "Hier 17:26:54" |
||
| 160 | } |
||
| 161 | |||
| 162 | c -> s |
||
| 163 | { |
||
| 164 | "header" : {action : "wait_event", version : 3}, |
||
| 165 | "page" : "chat" |
||
| 166 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 167 | "message_count" : 10, |
||
| 168 | "last_message_id" : 163, |
||
| 169 | "main_page" : 1, |
||
| 170 | "troll_id" : 45, |
||
| 171 | "conversations" : [ |
||
| 172 | { |
||
| 173 | "root" : 123, |
||
| 174 | "page" : 1, |
||
| 175 | "last_message_id" : 4 (pas obligatoire) |
||
| 176 | } |
||
| 177 | ] |
||
| 178 | } |
||
| 179 | |||
| 180 | s -> c |
||
| 181 | La première conversation est la principale (main). |
||
| 182 | L'ordre des conversation est le même que celui des données de l'utilisateur. |
||
| 183 | Le format de la date n'est pas formel. |
||
| 184 | first correpond au premier message de la conversation, vaut 'null' pour la conversation principale ainsi que pour les conversations vides. |
||
| 185 | { |
||
| 186 | "reply" : "new_message", |
||
| 187 | "conversations" : [ |
||
| 188 | { |
||
| 189 | "last_page" : true | false, |
||
| 190 | "first" : <message> | null, |
||
| 191 | "messages" : [ <message>, .. ] |
||
| 192 | } |
||
| 193 | ] |
||
| 194 | } |
||
| 195 | ou |
||
| 196 | { |
||
| 197 | "reply" : "message_updated", |
||
| 198 | "message_id" : 123, |
||
| 199 | "content" : "Salut poulpe", |
||
| 200 | "last_modification" : "Hier 17:26:54" |
||
| 201 | } |
||
| 202 | ou |
||
| 203 | { |
||
| 204 | "reply" : "new_troll", |
||
| 205 | "troll_id" : 123, |
||
| 206 | "message_id" : 12, |
||
| 207 | "content" : "Linux sera desktop ready en 2008 ?" |
||
| 208 | } |
||
| 209 | ou |
||
| 210 | <error> |
||
| 211 | |||
| 212 | |||
| 213 | === Wait event (page = admin) === |
||
| 214 | c -> s |
||
| 215 | { |
||
| 216 | "header" : {action : "wait_event", version : 3}, |
||
| 217 | "page" : "admin", |
||
| 218 | "last_troll" : 5 |
||
| 219 | } |
||
| 220 | |||
| 221 | s -> c |
||
| 222 | { |
||
| 223 | "reply" : "troll_modified", |
||
| 224 | "troll_id" : 3, |
||
| 225 | "content" : "plop" |
||
| 226 | } |
||
| 227 | ou |
||
| 228 | s -> c |
||
| 229 | { |
||
| 230 | "reply" : "troll_added", |
||
| 231 | "trolls" : |
||
| 232 | [ |
||
| 233 | { |
||
| 234 | "troll_id" : 5, |
||
| 235 | "content" : "plop", |
||
| 236 | "author" : "<Pseudo>" |
||
| 237 | "author_id" : 2 |
||
| 238 | } |
||
| 239 | ] |
||
| 240 | } |
||
| 241 | ou |
||
| 242 | s -> c |
||
| 243 | { |
||
| 244 | "reply" : "troll_deleted", |
||
| 245 | "troll_id" : 2 |
||
| 246 | } |
||
| 247 | ou |
||
| 248 | indique de mettre à jour la liste d'ips |
||
| 249 | s -> c |
||
| 250 | { |
||
| 251 | "reply" : "banned_ips_refresh" |
||
| 252 | } |
||
| 253 | |||
| 254 | |||
| 255 | === Envoie d'un troll === |
||
| 256 | c -> s |
||
| 257 | { |
||
| 258 | "header" : {action : "put_troll", version : 3}, |
||
| 259 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 260 | "content" : "Un bon troll velu !" |
||
| 261 | } |
||
| 262 | |||
| 263 | s -> c |
||
| 264 | <ok> |
||
| 265 | ou |
||
| 266 | <error> |
||
| 267 | |||
| 268 | |||
| 269 | === Modification d'un troll === |
||
| 270 | c -> s |
||
| 271 | { |
||
| 272 | "header" : {action : "mod_troll", version : 3}, |
||
| 273 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 274 | "troll_id" : 3, |
||
| 275 | "content" : "Un bon troll velu 2 !" |
||
| 276 | } |
||
| 277 | |||
| 278 | s -> c |
||
| 279 | <ok> |
||
| 280 | ou |
||
| 281 | <error> |
||
| 282 | |||
| 283 | |||
| 284 | === Suppression d'un troll === |
||
| 285 | c -> s |
||
| 286 | { |
||
| 287 | "header" : {action : "del_troll", version : 3}, |
||
| 288 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 289 | "troll_id" : 3 |
||
| 290 | } |
||
| 291 | |||
| 292 | s -> c |
||
| 293 | <ok> |
||
| 294 | ou |
||
| 295 | <error> |
||
| 296 | |||
| 297 | |||
| 298 | === Envoie message === |
||
| 299 | Le client envoie un message, le message peut répondre à un certain nombre d'autres messages. |
||
| 300 | "answer_to" n'est pas obligatoire. |
||
| 301 | |||
| 302 | c -> s |
||
| 303 | { |
||
| 304 | "header" : {action : "put_message", version : 3}, |
||
| 305 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 306 | "nick" : "Paul", |
||
| 307 | "content" : "Bonjour", |
||
| 308 | "answer_to" : [ 345, 532, ... ] |
||
| 309 | } |
||
| 310 | |||
| 311 | s -> c |
||
| 312 | <ok> |
||
| 313 | ou |
||
| 314 | <error> |
||
| 315 | |||
| 316 | |||
| 317 | === Slapage === |
||
| 318 | c -> s |
||
| 319 | { |
||
| 320 | "header" : {action : "slap", version : 3}, |
||
| 321 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 322 | "user_id" : 67, |
||
| 323 | "reason" : "blablabla" |
||
| 324 | } |
||
| 325 | |||
| 326 | s -> c |
||
| 327 | <ok> |
||
| 328 | ou |
||
| 329 | <error> |
||
| 330 | |||
| 331 | |||
| 332 | === Bannissement === |
||
| 333 | c -> s |
||
| 334 | { |
||
| 335 | "header" : {action : "ban", version : 3}, |
||
| 336 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 337 | "duration" : 15, // en minute |
||
| 338 | "user_id" : 67, |
||
| 339 | "reason" : "blablabla" |
||
| 340 | } |
||
| 341 | |||
| 342 | s -> c |
||
| 343 | <ok> |
||
| 344 | ou |
||
| 345 | <error> |
||
| 346 | |||
| 347 | |||
| 348 | === Liste des ip bannis === |
||
| 349 | c -> s |
||
| 350 | { |
||
| 351 | "header" : {action : "list_banned_ips", version : 3}, |
||
| 352 | "cookie" : "LKJDLAKSJBFLKASN" |
||
| 353 | } |
||
| 354 | |||
| 355 | s -> c |
||
| 356 | { |
||
| 357 | "reply" : "list_banned_ips", |
||
| 358 | "list" : [ |
||
| 359 | { |
||
| 360 | ip : "192.168.1.2", |
||
| 361 | remaining_time : "1h23" |
||
| 362 | users : [ |
||
| 363 | { |
||
| 364 | nick : "Pierre" , |
||
| 365 | login : "pierre" |
||
| 366 | } |
||
| 367 | ] |
||
| 368 | } |
||
| 369 | ] |
||
| 370 | } |
||
| 371 | |||
| 372 | |||
| 373 | === Débannissement === |
||
| 374 | c -> s |
||
| 375 | { |
||
| 376 | "header" : {action : "unban", version : 3}, |
||
| 377 | "cookie" : "LKJDLAKSJBFLKASN" |
||
| 378 | "ip" : "192.168.1.2" |
||
| 379 | } |
||
| 380 | |||
| 381 | s -> c |
||
| 382 | <ok> |
||
| 383 | ou |
||
| 384 | <error> |
||
| 385 | |||
| 386 | |||
| 387 | === Ajout d'une correction d'un messages === |
||
| 388 | Le client envoie un correctif sous la forme de texte supplémentaire à appondre au dernier messages. |
||
| 389 | Le message est appondu avec un " +++ " devant, par exemple : |
||
| 390 | > Gnome c'est mieux que KDE +++ Euh non ok, c'est faux |
||
| 391 | |||
| 392 | c -> s |
||
| 393 | { |
||
| 394 | "header" : {action : "correction", version : 3}, |
||
| 395 | "cookie" : "LKJDLAKSJBFLKASN", |
||
| 396 | "content" : "Euh non ok, c'est faux" |
||
| 397 | } |
||
| 398 | |||
| 399 | s -> c |
||
| 400 | { |
||
| 401 | "reply" : "correction", |
||
| 402 | "status" : "ok" | "error", |
||
| 403 | "message_error" : "blabla" |
||
| 404 | } |