public override async void OnMessage(WebSocket socket, WebSocketHandler handler, JsonData message) { var json = new JsonData(); var uid = long.Parse(message["uid"].ToString()); var userModel = ModelMgr.GetModel(ModelNames.User) as UserModel; if (userModel != null) { var list = new List <string>(); list.Add("uid=" + uid); var dataset = userModel.Query(list); if (dataset.Tables[0].Rows.Count > 0) { var row = dataset.Tables[0].Rows[0]; json["result"] = (int)ResultCode.Success; json["username"] = row["username"].ToString(); } else { json["result"] = (int)ResultCode.Failed; //结果码 } } else { json["result"] = (int)ResultCode.Failed; //结果码 } var retMssage = new WebSocketManager.Message() { CommandId = Protocal.ReqUserInfo, MessageType = MessageType.Json, Data = JsonMapper.ToJson(json) }; await handler.SendMessageAsync(socket, retMssage); }
public override async void OnMessage(WebSocket socket, WebSocketHandler handler, JsonData message) { base.OnMessage(socket, handler, message); var data = message["Data"]; var lobbyid = data["lobbyid"].ToString(); RoomInfo room = null; var lobby = LobbyMgr.GetLobby(lobbyid); if (lobby != null) { room = lobby.OnMate(socket); } var json = new JsonData(); if (room == null) { json["result"] = (int)ResultCode.Failed; } else { json["result"] = (int)ResultCode.Success; json["roomid"] = room.RoomId; } var retMssage = new WebSocketManager.Message() { CommandId = Protocal.ReqMate, MessageType = MessageType.Json, Data = JsonMapper.ToJson(json) }; await handler.SendMessageAsync(socket, retMssage); logger.Info("OnMessage: " + json["result"]); }
public override async void OnMessage(WebSocket socket, WebSocketHandler handler, JsonData message) { base.OnMessage(socket, handler, message); var lobbys = LobbyMgr.GetLobbys(); var json = new JsonData(); json["result"] = (int)ResultCode.Success; int i = 0; var subjson = new JsonData(); foreach (var de in lobbys) { subjson[i]["name"] = de.Value.lobbyName; subjson[i]["room"] = de.Value.roomCount; subjson[i]["user"] = de.Value.userCount; i++; } json["data"] = subjson; var retMssage = new WebSocketManager.Message() { CommandId = Protocal.ReqLobbyList, MessageType = MessageType.Json, Data = JsonMapper.ToJson(json) }; await handler.SendMessageAsync(socket, retMssage); }
public override async void OnMessage(WebSocket socket, WebSocketHandler handler, JsonData message) { var json = new JsonData(); var uid = long.Parse(message["uid"].ToString()); var seed = 10; var retMssage = new WebSocketManager.Message() { CommandId = Protocal.Battle, MessageType = MessageType.Json, Data = JsonMapper.ToJson(json) }; await handler.SendMessageAsync(socket, retMssage); }
public override async void OnMessage(WebSocket socket, WebSocketHandler handler, JsonData message) { this.handler = handler; var data = message["Data"]; var username = data["username"].ToString(); var password = data["password"].ToString(); var uid = 0L; var json = new JsonData(); var userModel = ModelMgr.GetModel(ModelNames.User) as UserModel; if (userModel != null) { var list = new List <string>(); list.Add("username=\"" + username + "\""); list.Add("password=\"" + password + "\""); //uid = userModel.ExistUser(list); } if (uid > 0L) { json["result"] = (int)ResultCode.Success; json["uid"] = uid; InitUser(uid, socket, userModel); } else { json["result"] = (int)ResultCode.Failed; } var retMssage = new WebSocketManager.Message() { CommandId = Protocal.Login, MessageType = MessageType.Json, Data = JsonMapper.ToJson(json) }; await handler.SendMessageAsync(socket, retMssage); logger.Info(username + " " + password); }
public override async void OnMessage(WebSocket socket, WebSocketHandler handler, JsonData message) { long uid = 0L; var data = message["Data"]; var username = data["username"].ToString(); var password = data["password"].ToString(); var values = new List <string>(); values.Add("\"" + username + "\""); values.Add("\"" + password + "\""); var userModel = ModelMgr.GetModel(ModelNames.User) as UserModel; if (userModel != null) { uid = userModel.AddUser(values); } var result = uid == 0 ? (int)ResultCode.Failed : (int)ResultCode.Success; var json = new JsonData(); json["result"] = result; //结果码 if (uid >= 0L) { json["uid"] = uid; //用户ID } var retMssage = new WebSocketManager.Message() { CommandId = Protocal.Register, MessageType = MessageType.Json, Data = JsonMapper.ToJson(json) }; await handler.SendMessageAsync(socket, retMssage); logger.Info("OnMessage: " + uid); }