コード例 #1
0
        void OnEvent_OnServerHello(object param)
        {
            var msg = param as Msg_G2C_Hello;

            LocalActorId = msg.LocalId;
            Debug.Log("OnEvent_OnServerHello " + LocalActorId);
        }
コード例 #2
0
        void OnEvent_OnServerMissFrame(object param)
        {
            Debug.Log($"OnEvent_OnServerMissFrame");
            var msg = param as Msg_RepMissFrame;

            _cmdBuffer.PushMissServerFrames(msg.frames, false);
        }
コード例 #3
0
        public void OnMsg_X2Y_RegisterDaemon(IDaemonProxy net, Deserializer reader)
        {
            var msg = reader.Parse <Msg_RegisterDaemon>();

            Debug.Log("OnMsg_X2Y_RegisterDaemon " + msg.ToString());
            //_netServerXS.Border(EMsgXS.X2S_RepMasterInfo, msg);
        }
コード例 #4
0
        protected void C2I_UserLogin(IIncommingMessage reader)
        {
            var msg = reader.Parse <Msg_C2I_UserLogin>();

            Debug.Log("C2I_UserLogin" + msg);
            ReqUserInfo(msg, reader);
        }
コード例 #5
0
        public void Upgrade(IEntity iEntity)
        {
            var entity      = iEntity as GameEntity;
            var playerCount = _gameConfigService.playerPrefabs.Count;
            var targetType  = entity.unit.detailType + 1;

            if (targetType >= playerCount)
            {
                Debug.Log($"hehe already max level can not upgrade");
                return;
            }

            var ecsPrefab = _gameConfigService.playerPrefabs[targetType] as ConfigUnit;
            var rawPos    = entity.pos.value;
            var rawDir    = entity.dir.value;

            ecsPrefab.SetComponentsTo(entity);
            entity.pos.value = rawPos;
            entity.dir.value = rawDir;
            if (!_constStateService.IsVideoLoading)
            {
                _viewService.DeleteView(entity.localId.value);
                _viewService.BindView(entity, (short)(ushort)ecsPrefab.asset.assetId, rawPos,
                                      DirUtil.GetDirDeg(rawDir));
            }
        }
コード例 #6
0
 public void Init(string ip, int port, string key)
 {
     _key       = key;
     this._ip   = ip;
     this._port = port;
     _listener  = new EventBasedNetListener();
     _listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) => {
         OnNetMsg(dataReader.GetRemainingBytes());
         dataReader.Recycle();
     };
     _listener.PeerConnectedEvent += (peer) => {
         UnityEngine.Debug.Log("Connected!!");
         _peer = peer;
         OnConnected?.Invoke();
     };
     _listener.PeerDisconnectedEvent += (peer, disconnectInfo) => {
         UnityEngine.Debug.Log("DisConnected!!");
     };
     _client = new NetManager(_listener)
     {
         DisconnectTimeout = 300000
     };
     _isInit = true;
     Debug.Log($"Try Connect to {ip}:{port}");
 }
コード例 #7
0
        public void OnMsg_X2Y_ReqMasterInfo(IDaemonProxy net, Deserializer reader)
        {
            var serverInfo = reader.Parse <Msg_ReqMasterInfo>().serverInfo;

            Debug.Log("OnMsg_X2Y_ReqMasterInfo " + serverInfo.ToString());
            var type = (EServerType)serverInfo.serverType;

            if (serverInfo.isMaster)
            {
                _type2MasterInfo[type] = serverInfo;
                _netServerYX.Border(EMsgYX.Y2X_BorderMasterInfo, new Msg_BorderMasterInfo()
                {
                    serverInfo = serverInfo
                });
            }

            if (_type2MasterInfo.Count > 0)
            {
                var infos = _type2MasterInfo.Values.ToArray();
                net.SendMsg(EMsgYX.Y2X_RepMasterInfo, new Msg_RepMasterInfo()
                {
                    serverInfos = infos
                });
            }
        }
コード例 #8
0
        public void OnMsg_Y2X_BorderMasterInfo(Deserializer reader)
        {
            var msg = reader.Parse <Msg_BorderMasterInfo>();

            Debug.Log("OnMsg_Y2X_RepMasterInfo " + msg.ToString());
            _netServerXS.Border(EMsgXS.X2S_BorderMasterInfo, msg);
        }
コード例 #9
0
        protected override void OnMasterServerInfo(ServerIpInfo info){
            if (info.ServerType == (byte) EServerType.DatabaseServer) {
                if (_netClientDS != null) return;
                Debug.Log("OnMasterServerInfo" + info);
                ReqOtherServerInfo(EServerType.DatabaseServer, (status, respond) => {
                    if (status != EResponseStatus.Failed) {
                        InitClientDS(respond.Parse<Msg_RepOtherServerInfo>().ServerInfo);
                    }
                });
            }

            if (info.ServerType == (byte) EServerType.LobbyServer) {
                if (_netClientLI != null) return;
                Debug.Log("OnMasterServerInfo" + info);
                ReqOtherServerInfo(EServerType.LobbyServer, (status, respond) => {
                    if (status != EResponseStatus.Failed) {
                        InitClientLI(respond.Parse<Msg_RepOtherServerInfo>().ServerInfo);
                    }
                });
                ReqOtherServerInfo(EServerType.LobbyServer, (status, respond) => {
                    if (status != EResponseStatus.Failed) {
                        lobbyInfo = respond.Parse<Msg_RepOtherServerInfo>().ServerInfo;
                    }
                }, EServerDetailPortType.TcpPort);
            }
        }
コード例 #10
0
 private void OnDBConn()
 {
     Debug.Log(" OnDBConn");
     _netClientDS.Send(EMsgDS.S2D_ReqUserInfo, new Msg_ReqAccountData()
     {
         account  = "LockstepPlatform",
         password = "******"
     });
     _netClientDS.Send(EMsgDS.S2D_ReqCreateUser, new Msg_ReqAccountData()
     {
         account  = "LockstepPlatform",
         password = "******"
     });
     _netClientDS.Send(EMsgDS.S2D_ReqCreateUser, new Msg_ReqAccountData()
     {
         account  = "jiepengtan",
         password = "******"
     });
     _netClientDS.Send(EMsgDS.S2D_ReqUserInfo, new Msg_ReqAccountData()
     {
         account  = "jiepengtan",
         password = "******"
     });
     _netClientDS.Send(EMsgDS.S2D_ReqUserInfo, new Msg_ReqAccountData()
     {
         account  = "LockstepPlatform",
         password = "******"
     });
     _netClientDS.Send(EMsgDS.S2D_ReqUserInfo, new Msg_ReqAccountData()
     {
         account  = "hehehe",
         password = "******"
     });
 }
コード例 #11
0
        void OnNet_ReqMissFrame(Player player, BaseFormater data)
        {
            var reqMsg        = data as Msg_ReqMissFrame;
            var nextCheckTick = reqMsg.StartTick;

            Debug.Log($"OnNet_ReqMissFrame nextCheckTick id:{player.localId}:{nextCheckTick}");
            var msg   = new Msg_RepMissFrame();
            int count = Math.Min(Math.Min((Tick - 1), allHistoryFrames.Count) - nextCheckTick,
                                 MaxRepMissFrameCountPerPack);

            if (count <= 0)
            {
                return;
            }
            var frames = new ServerFrame[count];

            for (int i = 0; i < count; i++)
            {
                frames[i] = allHistoryFrames[nextCheckTick + i];
                Debug.Assert(frames[i] != null);
            }

            msg.StartTick = frames[0].Tick;
            msg.Frames    = frames;
            SendTo(player, EMsgSC.G2C_RepMissFrame, msg, true);
        }
コード例 #12
0
        public bool Fire(int idx)
        {
            if (config == null)
            {
                return(false);
            }
            if (idx < 0 || idx > _skills.Count)
            {
                return(false);
            }

            //Debug.Log("TryFire " + idx);

            if (isFiring)
            {
                return(false);          //
            }
            var skill = _skills[idx];

            if (skill.Fire())
            {
                _curSkillIdx = idx;
                return(true);
            }

            Debug.Log($"TryFire failure {idx} {skill.CdTimer}  {skill.State}");
            return(false);
        }
コード例 #13
0
ファイル: Server.cs プロジェクト: kidfreedom/LockstepPlatform
        protected void OnMsg_S2M_RegisterServer(IServerProxy net, Deserializer reader)
        {
            Debug.Log("Add a server " + net.EndPoint.ToString());
            var msg = reader.Parse <Msg_RegisterServer>();

            net.ServerType = (EServerType)msg.serverInfo.serverType;
        }
コード例 #14
0
        public void DoUpdate(float deltaTime)
        {
            _networkService.SendPing(_simulatorService.LocalActorId, LTime.realtimeSinceStartupMS);
            _predictHelper.DoUpdate(deltaTime);
            int worldTick = _simulatorService.World.Tick;

            UpdatePingVal(deltaTime);

            //Debug.Assert(nextTickToCheck <= nextClientTick, "localServerTick <= localClientTick ");
            //Confirm frames
            IsNeedRollback = false;
            while (NextTickToCheck <= MaxServerTickInBuffer && NextTickToCheck < worldTick)
            {
                var sIdx   = NextTickToCheck % _bufferSize;
                var cFrame = _clientBuffer[sIdx];
                var sFrame = _serverBuffer[sIdx];
                if (cFrame == null || cFrame.tick != NextTickToCheck || sFrame == null ||
                    sFrame.tick != NextTickToCheck)
                {
                    break;
                }
                //Check client guess input match the real input
                if (object.ReferenceEquals(sFrame, cFrame) || sFrame.Equals(cFrame))
                {
                    NextTickToCheck++;
                }
                else
                {
                    IsNeedRollback = true;
                    break;
                }
            }

            //Request miss frame data
            int tick = NextTickToCheck;

            for (; tick <= MaxServerTickInBuffer; tick++)
            {
                var idx = tick % _bufferSize;
                if (_serverBuffer[idx] == null || _serverBuffer[idx].tick != tick)
                {
                    break;
                }
            }

            MaxContinueServerTick = tick - 1;
            if (MaxContinueServerTick <= 0)
            {
                return;
            }
            if (MaxContinueServerTick < CurTickInServer || // has some middle frame pack was lost
                _nextClientTick >
                MaxContinueServerTick + (_maxClientPredictFrameCount - 3) //client has predict too much
                )
            {
                Debug.Log("SendMissFrameReq " + MaxContinueServerTick);
                _networkService.SendMissFrameReq(MaxContinueServerTick);
            }
        }
コード例 #15
0
        void OnPursuingFrame()
        {
            _constStateService.IsPursueFrame = true;
            Debug.Log($"PurchaseServering curTick:" + _world.Tick);
            var progress = _world.Tick * 1.0f / _cmdBuffer.CurTickInServer;

            EventHelper.Trigger(EEvent.PursueFrameProcess, progress);
        }
コード例 #16
0
 private void OnDBMasterConn()
 {
     Debug.Log(" OnDBMasterConn");
     _netClientOMS.Send(EMsgMS.S2M_ReqOtherServerInfo, new Msg_ReqOtherServerInfo()
     {
         serverType = (byte)EServerType.DatabaseServer
     });
 }
コード例 #17
0
        public void OnMsg_S2X_ReqMasterInfo(IServerProxy net, Deserializer reader)
        {
            var msg = reader.Parse <Msg_ReqMasterInfo>();

            Debug.Log("OnMsg_S2X_ReqMasterInfo " + msg.ToString());
            net.ServerType    = (EServerType)msg.serverInfo.serverType;
            msg.serverInfo.ip = net.EndPoint.Address.ToString();
            _netClientYX.Send(EMsgYX.X2Y_ReqMasterInfo, msg);
        }
コード例 #18
0
 public void DoDestroy()
 {
     Debug.Log("DoDestroy");
     _netTcp.SendMessage(EMsgSC.C2L_LeaveRoom, new Msg_C2L_LeaveRoom().ToBytes());
     _netUdp?.DoDestroy();
     _netTcp?.DoDestroy();
     _netTcp = null;
     _netUdp = null;
 }
コード例 #19
0
 void OnEvent_LevelLoadDone(object param)
 {
     Debug.Log($"OnEvent_LevelLoadDone " + _constStateService.IsReconnecting);
     if (_constStateService.IsReconnecting || _constStateService.IsVideoMode ||
         _constStateService.IsClientMode)
     {
         StartSimulate();
     }
 }
コード例 #20
0
 public void OnSkillDone(Entity *ptr
                         , ref SkillData skillData
                         )
 {
     if (_id2EntityView.TryGetValue(ptr->LocalId, out var uView))
     {
         uView.OnSkillDone(skillData.AtkRange);
     }
     Debug.Log("OnSkillDone");
 }
コード例 #21
0
        protected void OnMsg_M2S_RepOtherServerInfo(Deserializer reader)
        {
            var msg  = reader.Parse <Msg_RepOtherServerInfo>();
            var info = msg.serverInfo;

            if (EServerType.DatabaseServer == (EServerType)info.serverType)
            {
                Debug.Log("OnMsg_M2S_RepOtherServerInfo " + msg.ToString());
                InitNetClient(ref _netClientDS, info.ip, info.port, OnDBConn);
            }
        }
コード例 #22
0
        void OnHashMatchResult(int tick, long hash, bool isMatched)
        {
            if (isMatched)
            {
                _hashCodes[tick] = null;
            }

            if (!isMatched)
            {
                Debug.Log($"!!!!!!!!!!!! Hash not match tick{tick} hash{hash} ");
            }
        }
コード例 #23
0
        public void RollbackTo(int tick, int maxContinueServerTick, bool isNeedClear = true)
        {
            if (tick < 0)
            {
                Debug.LogError("Target Tick invalid!" + tick);
                return;
            }

            Debug.Log($" Rollback diff:{Tick - tick} From{Tick}->{tick}  maxContinueServerTick:{maxContinueServerTick} {isNeedClear}");
            _timeMachineService.RollbackTo(tick);
            _commonStateService.SetTick(tick);
            Tick = tick;
        }
コード例 #24
0
        public void SendInput(Msg_PlayerInput input)
        {
            _tick2SendTimestamp[input.Tick] = LTime.realtimeSinceStartupMS;
#if DEBUG_SHOW_INPUT
            var cmd         = input.Commands[0];
            var playerInput = new Deserializer(cmd.content).Parse <Lockstep.Game.PlayerInput>();
            if (playerInput.inputUV != LVector2.zero)
            {
                Debug.Log($"SendInput tick:{input.Tick} uv:{playerInput.inputUV}");
            }
#endif
            _networkService.SendInput(input);
        }
コード例 #25
0
ファイル: Server.cs プロジェクト: kidfreedom/LockstepPlatform
        public void OnMsg_X2S_BorderMasterInfo(Deserializer reader)
        {
            var msg = reader.Parse <Msg_BorderMasterInfo>();

            Debug.Log("OnMsg_X2S_BorderMasterInfo " + msg.ToString());
            if (msg.serverInfo.serverType == (byte)serverType)
            {
                Debug.Log("OnMsg_X2S_RepMasterInfo " + msg.ToString());
                InitClientMS(msg.serverInfo);
            }

            OnMasterServerInfo(msg.serverInfo);
        }
コード例 #26
0
ファイル: Server.cs プロジェクト: kidfreedom/LockstepPlatform
 private void InitClientMS(ServerIpInfo msg)
 {
     InitNetClient(ref _netClientMS, msg.ip, msg.port, () => {
         Debug.Log("Connect Master " + serverType);
         _netClientMS.Send(EMsgMS.S2M_RegisterServer, new Msg_RegisterServer()
         {
             serverInfo = new ServerIpInfo()
             {
                 serverType = (byte)serverType
             }
         });
     }
                   );
 }
コード例 #27
0
        public void SendTo(Player player, EMsgSC type, ISerializable body, bool isNeedDebugSize = false)
        {
            var writer = new Serializer();

            writer.PutByte((byte)type);
            body.Serialize(writer);
            var bytes = Compressor.Compress(writer);

            if (isNeedDebugSize)
            {
                Debug.Log($"msg :type {type} size{bytes.Length}");
            }

            player.SendRoom(bytes);
        }
コード例 #28
0
        protected void G2C_GameStartInfo(object reader)
        {
            var msg = reader as Msg_G2C_GameStartInfo;

            HasRecvGameDta = true;
            GameStartInfo  = msg;
            _handler.OnGameStartInfo(msg);
            //TODO temp code
            HasConnGameTcp   = true;
            HasConnGameUdp   = true;
            CurGameState     = EGameState.Loading;
            _curLoadProgress = 1;
            EventHelper.Trigger(EEvent.OnGameCreate, msg);
            Debug.Log("G2C_GameStartInfo");
        }
コード例 #29
0
ファイル: Server.cs プロジェクト: kidfreedom/LockstepPlatform
 private void InitClientXS()
 {
     Debug.Log("InitClientXS " + _allConfig.daemonPort);
     InitNetClient(ref _netClientXS, "127.0.0.1", _allConfig.daemonPort,
                   () => {
         Debug.Log("OnConnectedDaemon " + _allConfig.daemonPort);
         _netClientXS.Send(EMsgXS.S2X_ReqMasterInfo, new Msg_ReqMasterInfo()
         {
             serverInfo = new ServerIpInfo()
             {
                 isMaster   = _serverConfig.isMaster,
                 port       = _serverConfig.masterPort,
                 serverType = (byte)serverType
             }
         });
     });
 }
コード例 #30
0
ファイル: Server.cs プロジェクト: kidfreedom/LockstepPlatform
        protected void OnMsg_S2M_ReqOtherServerInfo(IServerProxy net, Deserializer reader)
        {
            var msg  = reader.Parse <Msg_ReqOtherServerInfo>();
            var type = (EServerType)msg.serverType;

            Debug.Log("OnMsg_S2M_ReqOtherServerInfo " + type);
            if (type == serverType)
            {
                //TODO
                var info = GetSlaveServeInfo();
                Debug.Log("GetSlaveServeInfo " + info);
                net.SendMsg(EMsgMS.M2S_RepOtherServerInfo, new Msg_RepOtherServerInfo()
                {
                    serverInfo = info
                });
            }
        }