public void OnSocketListenerMessageReceiveConnectEx(ServerClient client, ServiceDesc desc) { var clientId = desc.ClientId; var characterId = desc.CharacterId; //ClientRouting server; if (desc.ServiceType == 2) { //连接的是Gate var gateGuid = (int)clientId; client.UserData = gateGuid; GateProxy gateProxy; if (mGates.TryGetValue(gateGuid, out gateProxy)) { gateProxy.Gate = client; } else { mGates[gateGuid] = new GateProxy { Gate = client }; } } }
public virtual CharacterInfo OnSocketListenerMessageReceivePrepareDataEx(ServerClient client, ServiceDesc desc, bool isNeedSendReply = true) { //var clientId = desc.ClientId; //ClientRouting server; using (var ms = new MemoryStream(desc.Data)) { var msg = Serializer.Deserialize <PrepareDataMessage>(ms); var characterId = msg.CharacterId; var clientId = msg.ClientId; GateProxy gate = null; if (client.UserData == null) { if (!mGates.TryGetValue((int)(msg.ClientId >> 48), out gate)) { Logger.Error( "OnSocketListenerMessageReceivePrepareDataEx ------- mFromCharacterId2Server.TryGetValue Has -- {0}", msg.ClientId); return(null); } } else if (!mGates.TryGetValue((int)client.UserData, out gate)) { Logger.Error( "OnSocketListenerMessageReceivePrepareDataEx ------- mFromCharacterId2Server.TryGetValue Has -- {0}", msg.ClientId); return(null); } else { if (clientId != gate.Gate.ClientId) { Logger.Error( "OnSocketListenerMessageReceivePrepareDataEx ------- ClientId not same! old={0},new={1}", characterId, clientId); } } //创建角色管理 var character = CreateCharacter(characterId); character.Server = SelectServerForCharacter(characterId); character.ServerId = msg.ServerId; character.Gate = gate; character.ClientId = clientId; mCharacterInfoManager.AddOrUpdate(characterId, character, (arg1, arg2) => { Logger.Error( "OnSocketListenerMessageReceivePrepareDataEx ------- mFromCharacterId2Server.TryGetValue Has -- {0}", characterId); return(character); }); //统计服务器区的角色 ConcurrentDictionary <ulong, int> bag = null; var ServerId = (uint)msg.ServerId; mFromServerId2CharacterId.AddOrUpdate(ServerId, key => { bag = new ConcurrentDictionary <ulong, int>(); return(bag); }, (key, oldValue) => { bag = oldValue; return(oldValue); }); bag.AddOrUpdate(msg.CharacterId, 0, (arg1, arg2) => { Logger.Error( "OnSocketListenerMessageReceivePrepareDataEx ------- mFromServerId2CharacterIdbag Add Has,s={0},c={1}", ServerId, characterId); return(0); }); PlayerLog.WriteLog(10003, "AddOrUpdate ClientId={0},characterId={1}", msg.ClientId, msg.CharacterId); //维护ClientId -> Character(考虑删除) mFromClientId2CharacterId.AddOrUpdate(msg.ClientId, msg.CharacterId, (arg1, arg2) => { Logger.Error("OnSocketListenerMessageReceivePrepareDataEx oldCharacterId={0},newCharacterId={1}", arg2, characterId); return(msg.CharacterId); }); if (isNeedSendReply) { client.SendMessage(desc); } Logger.Info("Reply PrepareData {0} {1}", mServiceName, desc.CharacterId); return(character); } }