ONLINE CHESS

帮助   其他游戏  
    

Sequence

login

sequenceDiagram player1 ->>+ server: [connect] server -->>- player1: clientid player1 ->> + server : join Room server ->> server : new room server -->> - player1 : Room info player2 ->> + server : join Room server ->> server : room found server -->> player2 : Room info server -->>player1 : chess status / turn /startgame server -->> - player2 : chess status / turn/startgame player2 ->>+ server : leaveroom server -->>- player1 : leaveroom alt 断线 player1 -->+ server : X server ->> server : room destory server -->>- player2 : leave end

start game

sequenceDiagram player1 ->> + server : move server ->> server : [remember 1stclientid.1sticolor] server ->> server : [set player color,played2 color] server -->> player1 : firstopen/chessstatus/turn.clientid server -->> - player2 : firstopen/chessstatus/turn.clientid player1 ->> + server : move server -->> - player1 : error(move fail) player1 ->> + server : move server -->> player1 : status server -->> - player2 : status player2 ->> + server : move server -->> player1 : status/turn/win/ server -->> - player2 : status/turn/win/ alt 认输 player1 -->>+ server : 认输 server -->> player2 : status/turn/win/fail server -->> - player1 : status/turn/win/fail end alt 求和 player1 -->>+ server : askpeace server -->> - player2 : askpeace player2 -->>+ server : peaceok / nopeace server -->> player2 : status/win/peace server -->> - player1 : status/win/peace end

sign up

sequenceDiagram player1 ->> + server : signup (username,password) server ->> server : find db/save db server -->> - player1 : signupok/signupfail player1 ->> + server : login (username,password) server ->> server : find db server -->> - player1 : loginok.token/loginfail

Status

Room status

stateDiagram-v2 state "empty (没人)" as empty state " someone (有人)" as someone state " full (满员)" as full state " allready (全员准备好了)" as allready state " ingame (全员游戏中)" as ingame [*] --> empty: new empty--> someone : joinroom someone --> full : joinroom full --> someone : leaveroom \n logoff full --> allready : ready allready --> full : unready \n logoff allready --> someone: leaveroom \n logoff allready --> ingame : stargame ingame --> full : endgame ingame --> someone : endgame someone --> empty : leaveroom\n logoff ingame --> ingame: logoff \n leavegame=leaveroom

User status

stateDiagram-v2 [*] --> new online -->stop stop --> removed removed --> [*] new -->online: login state online { direction LR [*] --> visite : new visite--> inroom : joinroom inroom -->visite:leaveroom inroom --> ready :ready ready --> ingame :allready state ingame { [*]-->myturn [*]-->otherturn myturn --> otherturn otherturn --> myturn otherturn-->[*] myturn-->[*] } ingame --> inroom : 游戏结束 visite--> [*] } online --> 临时断线:X 临时断线-->online:reconnect 临时断线 -->stop : 超时
stateDiagram direction LR state "game ready" as A state "game start" as B state "game end" as C [*] --> A A --> B B --> C state B { direction LR myturn --> otherturn otherturn --> myturn }

session object 状态

stateDiagram-v2 [*] --> online online --> brokenline brokenline --> online online -->stop stop --> removed removed --> [*]

conn object 状态

stateDiagram-v2 [*] --> online online --> stop stop --> removed removed --> [*]

new connect

flowchart TD style findsess stroke-width:4px,fill:#ff0 style qsess stroke-width:4px,fill:#ff0 st[start]-->|newconnect|newconnect(client放 connects map) newconnect-->qsess{{用户申请session?}} qsess-->|用户自己给session|findsess{{服务器找sessionid\n找到session?}} qsess-->|yes|newsess newsess-->addsess[add session map] findsess-->|yes|kickoldconn[oldcnn.disconnect=true;\nsession.dis=true;\n ;断开旧conn;] findsess-->|No|newsess[login\n服务器new session] kickoldconn-->linkconn[link new connection] linkconn-->loadstatus[ 发送旧状态\n把缓存的信息发给新conn\n 继续游戏] loadstatus-->e[end] addsess-->e

get message

flowchart TD style findsess stroke-width:4px,fill:#ff0 style fincclient stroke-width:4px,fill:#ff0 style sessq stroke-width:4px,fill:#ff0 style connq stroke-width:4px,fill:#ff0 style tmpdistimeout stroke-width:4px,fill:#ff0 st[收消息gconn,msg]-->fincclient{{根据 gconn 找 client}} fincclient -->|找到|findsess{{client找session}} fincclient -->|没找到|excep[异常] findsess-->|找到|sessq{{session看是登录用户还是非登录用户}} findsess-->|没找到|nologin[非登录用户]

send message

--- title: Send Message --- flowchart TD style findsess stroke-width:4px,fill:#ff0 style findconn stroke-width:4px,fill:#ff0 style sessq stroke-width:4px,fill:#ff0 style connq stroke-width:4px,fill:#ff0 style tmpdistimeout stroke-width:4px,fill:#ff0 st[发消息session,msg]-->findsess{{根据 sessionID 找 session}} findsess-->|yes找到|sessq{{session status ?}} findsess-->|找不到|sendfail[发送失败] sendfail-->e sessq-->|online|findconn{{根据session找conn}} sessq-->|tmp_dis|tmpdistimeout{{临时断线超时?}} tmpdistimeout -->|yes|tmpdis(临时断线,等待重连) tmpdistimeout -->|no|removesess tmpdis-->buffermsg sessq-->|stop/removed|removesess[set stop\n从map中删除session] removesess-->sendfail findconn-->|找到conn|connq{{ conn status ?}} findconn-->|找不到conn|buffermsg[remove session] connq-->|online|sendmsg(send msg) connq-->|stop/removed|buffermsg(buffer msg) sendmsg-->|成功|e sendmsg-->|失败|fail[设置conn.stop=true] fail-->buffermsg buffermsg-->e[结束]
https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.6.1/mermaid.min.js