/// <summary> /// 处理登录请求 /// </summary> /// <param name="client"></param> /// <param name="dto"></param> private void HandleLogin(ClientPeer client, AccountDto dto) { SingleExec.Exec(() => { if (!DatabaseManager.IsUserNameExist(dto.username)) { client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.userNotFound); return; } if (DatabaseManager.IsOnline(dto.username)) { client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.userOnline); return; } if (DatabaseManager.IsPasswordMatch(dto.username, dto.passwordHash)) { //设置登录状态 DatabaseManager.Login(dto.username, client); //登录成功 client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.success); } else { client.SendNetMsg(OpCode.account, AccountCode.loginSRes, AccountReturnCode.passwordNotMatch); } }); }
private void HandleGetRankList(ClientPeer client) { SingleExec.Exec(() => { RankListDto dto = DatabaseManager.GetRankListDto(); client.SendNetMsg(OpCode.account, AccountCode.getRankListSRes, dto); }); }
/// <summary> /// 获取当前客户端登录用户的信息 /// </summary> /// <param name="client"></param> private void HandleGetUserInfo(ClientPeer client) { SingleExec.Exec(() => { UserInfoDto dto = DatabaseManager.CreateUserInfoDto(client.userId); client.SendNetMsg(OpCode.account, AccountCode.getUserInfoSRes, dto); }); }
/// <summary> /// 处理客户端的注册请求 /// </summary> private void HandleRegister(ClientPeer client, AccountDto dto) { SingleExec.Exec(() => { if (DatabaseManager.IsUserNameExist(dto.username)) { client.SendNetMsg(OpCode.account, AccountCode.registerSRes, AccountReturnCode.userExist); return; } try { DatabaseManager.CreateUser(dto.username, dto.passwordHash); client.SendNetMsg(OpCode.account, AccountCode.registerSRes, AccountReturnCode.success); } catch (MySqlException e) { Console.WriteLine(e); } }); }
public override void Broadcast(int opCode, int subOpCode, object message, ClientPeer ignoreClient = null) { foreach (var item in userDict) { ClientPeer client = item.Value.client; if (client == ignoreClient) { continue; } client.SendNetMsg(opCode, subOpCode, message); } }
public override void Broadcast(int opCode, int subOpCode, object message, ClientPeer ignoreClient = null) { foreach (PlayerInfo item in playerList) { ClientPeer client = item.client; if (client == ignoreClient) { continue; } client.SendNetMsg(opCode, subOpCode, message); } }
private void HandleEnterRoom(ClientPeer client) { if (Sessions.matchSession.IsMatching(client)) // 已在队列中则不管 { return; } //先进入房间 MatchRoom room = Sessions.matchSession.EnterRoom(client); UserInfoDto userInfoDto = DatabaseManager.CreateUserInfoDto(client.userId); //然后向其他房间内用户广播进入房间信息 room.Broadcast(OpCode.match, MatchCode.EnterBrd, userInfoDto, client); //最后向客户端返回当前的房间信息 MatchRoomDto matchRoomDto = room.CreateMatchRoomDto(); client.SendNetMsg(OpCode.match, MatchCode.EnterSRes, matchRoomDto); }