自己写的五子棋 客户端及服务端协议
五子棋初步计划采用json协议,采用WebSocket通信 服务端命令包括: 游戏公告 获取房间列表第x页数据 xx玩家加入了xx房间 xx玩家离开了xx房间 xx玩家准备游戏 xx玩家将xx请离房间 刷新一个房间的数据 进入准备倒计时xx秒 返回用户名字 返回xx用户的信息(名字,id,等级,胜率,逃跑率,战绩) 房间数据 当前在线人数 发起邀请 准备游戏 开始游戏 离开房间 发送dialog信息 发送toast信息 发送异常信息 落子 赢棋/输棋 xx玩家认输 xx玩家已掉线 xx玩家发送对话信息 刷新棋盘 刷新棋盘上指定格子数据 客户端命令包括: 登录游戏(返回uuid数据) 二次登录游戏 获取游戏公告 获去当前用户名字 创建房间 加入一个房间 踢人 离开房间 准备游戏 获取棋盘数据 获取指定格子的数据 获取房间的人数 获取房间名字 悔棋 下子 发送对话信息 棋局认输 获取当前棋子类型(黑子/白子)
服务器协议
———————————————————————————————分割线——————————————————————————————————————————————————— 注:json数据中包含的[base64]语句,表示此段内容为加密数据 //游戏公告 {action:"Announcement",text="这是一个简单的游戏公告"}
//注册成功
//登录成功 msg表示提示语句 {action:"login",isLogin:"true",time:"363737%3",msg:"登录成功!"} //登录失败 msg表示失败原因 {action:"login",isLogin:"false",msg:"用户不存在!"} //向客户端发送游戏公告 {action:"announcement",msg:"这是公告内容"} //获取房间列表第x页数据 {action:"roomList", list: [ [ { user:"玩家1" userId : "34" isPrepare:"true" } , { user:"玩家2" userId : "35" isPrepare:"true" } ] , [ ...... ] ] } //xx玩家加入了xx房间 {action:"joinRoom",userId:"3",user:"玩家1",roomId="4",roomName="房间4"} //xx玩家离开了xx房间 {action:"exitRoom",userId:"3",user:"玩家1"} //xx玩家准备游戏 {action:"prepare",userId:"3",user:"玩家1"} //xx玩家将xx请离房间 {action:"moveOut",userId:"3",user:"玩家1",outUser="玩家xx",OutUserId="2"} //刷新一个房间的数据 {action:"refreshRoom", users: [ {userId:"3",user:"玩家1",isPrepare:"true"} , {userId:"5",user:"玩家2",isPrepare:"true" } ] } //进入准备倒计时xx秒 {action:"countdown",roomId:"3",second:"10"} //返回用户名字 {action:"userInfo",userName:"用户名"} //返回xx用户的信息(头像,名字,id,等级,胜率,逃跑率,战绩) {action:"userInfo",icon:"http://app.yzjlb.net/app/icon/11.jpg",user:"玩家",userId:"5",lv:"1",winningRat:"45",escapeRate:"1",warRecord:"308"} //房间数据 {action:"roomInfo",userList: [ {user:"玩家1",userId:"5"} , {user:"玩家2",userId:"7"} ] } //当前在线人数 {action:"onlineInfo",nums:"20"} //房间人数 {action:"roomSons",nums:2} //发起邀请 {action:"Invitation",invitationuser:"玩家2",invitationUserId:"4"} //准备游戏 {action:"prepare",user:"玩家",userId:"3"} //开始游戏 {action:"startGame"} //离开房间 {action:"",user:"",userId:""} //发送dialog信息 {action:"dialog",id:"3",msg:"对话框内容",ok="确定",cancel="返回"} //发送toast信息 {action:"toast",id:"4",msg:"toast内容"} //发送异常信息 {action:"error",id:"403",msg:""} //落子 {action:"drop",step:"39",user:"玩家1",userId:"4",x:"3",y:"4"} //赢棋/输棋 {action:"chessEnd",isWin:"true"} //xx玩家认输 {action:"userEnd",user:"玩家",userId:"3"} //xx玩家已掉线 {action:"userDrop",user:"玩家",userId:"3"} //xx玩家发送对话信息 {action:"msg",user:"玩家",userId:"3"} //刷新棋盘 棋盘数据用012表示(0表示空,1表示白棋,2表示黑棋) {action:"chessboard",info:"0001122...."} //刷新棋盘上指定格子数据 {action:"refreshLattice",x:"3",y:"4",type:1} //当前下棋玩家为:玩家1 {action:"playUser",user:"玩家1",userId:"3"} //返回棋子类型 0黑 1白 {action:"chessType",type:"0"}
客户端协议
———————————————————————————————分割线——————————————————————————————————————————————————— 登录游戏(http post请求) 网址:http://app.yzjlb.net/app/gobang/info.php post内容:type=login&user=玩家1&pass=md5xxxxxx 参数: type=login 表示登录 user=玩家1 用户名 pass 密码的两次md5 md5(md5($pass)) 成功后返回:{action:"login",type:"ok",uuid:"hdhdhdjysjsh"} 失败后返回:{action:"login",type:"error",msg:"密码错误!"}
登录游戏(返回uuid数据)(无效,请使用二次登录) {action:"login",userName:"用户名",pwd:"md5fhssgcgjxx",version:"1.0",type:"json",time:"46336444"}
二次登录游戏 {action:"login2",userName:"用户名",type:"json",uuid:"hdhdhdjduehcidjsmjssm"} 获取游戏公告 {action:"getAnnouncement"} 获取房间列表第x页数据 {action:"getRoomList",page:x} 获去当前用户名字 {action:"userInfo"} 创建房间 {action:"createRoom",name:"房间1"} 加入一个房间 {action:"joinRoom",roomId:"23",roomName:"房间23"} 踢人 {action:"kick",userId:"23"} 离开房间 {action:"exitRoom",userId:"23"} 准备游戏 {action:"prepare",userId:"23"} 获取棋盘数据 {action:"getChessboardData",type:"chars"} 获取指定格子的数据 {action:"getChessboardXY",x:"1",y:"1"} 获取房间的人数 {action:"getRoomSons",roomId:"2"} 获取房间名字 {action:"getRoomName",roomId:"2"} 悔棋 {action:"regretChess",userId:"2"} 下子 {action:"drop",x:"2",y:"3"} 发送对话信息 {action:"sendMsg",msg:""} 棋局认输 {action:"concedeDefeat"} 获取当前棋子类型(黑子/白子) {action:"getChessType"}
发表评论