/// <summary> /// 创建角色 /// </summary> public void Creat(ClientPeer client, string name) { SingleExecute.Instance.Execute(() => { //这个客户端是不是非法登陆 if (!accountCache.IsOnline(client)) { //非法登陆 user.Set("非法登陆"); client.StartSend(OpCode.USER, UserCode.CREAT_SRES, user); Console.WriteLine("非法登陆"); return; } //获取账号id int accountId = accountCache.GetID(client); //判断有没有角色 if (userCache.IsExist(accountId)) { //重复创建 user.Set("重复创建"); client.StartSend(OpCode.USER, UserCode.CREAT_SRES, user); Console.WriteLine("重复创建"); return; } //创建角色 userCache.Creat(name, accountId); user.Set("创建角色成功"); client.StartSend(OpCode.USER, UserCode.CREAT_SRES, user); Console.WriteLine("创建角色成功"); }); }
public void OnDisConnect(MOBAClient client) { //下线 *** 这里要通过客户端获取到玩家账号ID,再用账号ID获取到玩家ID,否则会报空 int accountID = accountCache.GetID(client); int playerID = playerCache.GetID(accountID); battleCache.OffLine(client, playerID); }
public void OnDisConnect(MOBAClient client) { //下线的时候,通知在线好友,显示离线状态 //***这里要通过客户端获取到玩家账号ID,再用账号ID获取到玩家ID,否则会报空 int accountID = accountCache.GetID(client); int playerID = playerCache.GetID(accountID); PlayerModel playerModel = playerCache.GetPlayerModel(playerID); if (playerModel != null) { foreach (int friendID in playerModel.FriendIdList) { if (!playerCache.IsOnLine(friendID)) //因为GetPlayerModel,GetClient是获取在线玩家的数据 { continue; } MOBAClient friendClient = playerCache.GetClient(friendID); Send(friendClient, OperationCode.PlayerCode, OpPlayer.FriendOnlineState, 1, "好友玩家下线", playerModel.Id); } } matchCache.OffLine(client, playerID); playerCache.OffLine(client); }