- no need to do server discovery, manual enter it on client startup - let server be a idiot, just use client provided information to do task and decide what to do - let client keep their status, and send what should lobby server do for them - lobby should keep each users state and ip, port, for sending msg - client should do all the jobs flow - server is just act like a tool for client, not a controler - read write to sql table function share a lock(just 1 for 2 table) for prevent race condition Q : how client let user choice what do do, and simutanously listen for invitation A: use select do asycnronize console input and socket input ======== server ========================================================= (A) - open_lobby() : enter port info, open a socket and listen, print server's ip,port info - create user table, game table and connect to mysql (B) - user_exist_check - user_register(act,username,hash_passwd)-->{success?, msg} check if user exist? (C) - check user status and exist? - match password if match: update status(also check if last is not log out, send notify to old ipport for serve logout) generate token store client connect info(ip, port) after client ack, update table and status (D) - logout(token) remove online state and connect information remove room create by the client (E) - display_user(): no need to check user's token sql select user not offline - display_room(): sql select room is public and their status (F) - create_room(): check if the user is idle and login room_type: public, private roome info,p1 p2 - invite_peer(): check p2's login status send peer invite to p2, wait respond(with timeout 15s) update user_status notify invite status to p1(accept, reject, timeout, failed?) [if success] ask p1 game room's ip port send game room conn info to p2 [if failed] update user status - notify_game_start(p1,p2 roomid): update p1,p2 status and game room status (H) - add to public(): check p2 status update game table, user table ========== client ============================= msg_sender(json)-->status code, received data handle connection error, send and receive request <--> game lobby user_reg(): ask user to set name and passwd, hash it and sent to server use the return status code to print msg or ask user to provie info again login(): ask username, check exist? ask passwd, hash it and send to server(name,hashed_passwd) handle server response store token bring to in_menu display_user display_room logout(): send token to server clear global var token kick user to out_menu display_user(), display_room() : check if user is login, and is at lobby trigger by user login success create_room(): check login status ask room type ask game type send room create to server list user ask invite join_public room(): send join to server wait serve response create game server send game server's conn info to lobby game_server1() game_client1() game_server2() game_client2() in_menu: create room(room type? game type?) join public room? wait invitation(control-C to break and return to in_menu) list room list user logout out_menu: client exit login