Exemplo n.º 1
0
        MessageHandleResult LoginHandler(
            NetConnection connection,
            ByteBuffer byteBuffer,
            NetIncomingMessage message)
        {
            Msg_SC_Login msg = InstancePool.Get <Msg_SC_Login>();

            Msg_SC_Login.GetRootAsMsg_SC_Login(byteBuffer, msg);
            if (!msg.Success)
            {
                GameStateLog.Error("Login failed:" + msg.Error);
                TransitTo <Error>(msg.Error);
            }
            else
            {
                game.id = msg.Id;
                GameStateLog.Info("Login success, game id:" + msg.Id);

                Msg_SC_UpdatePlayers updateplayers = InstancePool.Get <Msg_SC_UpdatePlayers>();
                msg.GetPlayers(updateplayers);
                PlayerManagerClient.Instance.UpdatePlayers(updateplayers);
                GameStateLog.Info("Update players");

                TransitTo <DataFullUpdate>();
            }
            return(MessageHandleResult.Finished);
        }
Exemplo n.º 2
0
 void FullUpdateRequest()
 {
     using (var builder = MessageBuilder.Get())
     {
         FlatBufferBuilder fbb = builder.fbb;
         Msg_CS_FullUpdate.StartMsg_CS_FullUpdate(fbb);
         fbb.Finish(Msg_CS_FullUpdate.EndMsg_CS_FullUpdate(fbb).Value);
         var msg = game.netlayer.CreateMessage(MessageID.Msg_CS_FullUpdate, fbb);
         game.netlayer.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
     }
     GameStateLog.Info("full update request");
 }
Exemplo n.º 3
0
        MessageHandleResult SnapshotHandler(
            NetConnection connection,
            ByteBuffer byteBuffer,
            NetIncomingMessage message)
        {
            Msg_SC_Snapshot snapshot = InstancePool.Get <Msg_SC_Snapshot>();

            Msg_SC_Snapshot.GetRootAsMsg_SC_Snapshot(byteBuffer, snapshot);
            SyncManagerClient.Instance.FullUpdate(snapshot);
            GameStateLog.Info("apply full update");
            TransitTo <InGame>();

            return(MessageHandleResult.Finished);
        }
Exemplo n.º 4
0
 protected override void Update()
 {
     if (game.netlayer.connectionStatus != NetConnectionStatus.Connected &&
         (mTimer -= Time.deltaTime) <= 0f)
     {
         mTimer = 5f;
         if (mAttempts++ >= 3)
         {
             TransitTo <Error>("reconnect timeout");
             return;
         }
         ConnectAttempt();
         GameStateLog.Info("reconnect attempt #" + mAttempts);
     }
 }
Exemplo n.º 5
0
 void OnNetStatusChanged(UdpConnector netlayer, NetConnectionStatus status, string reason)
 {
     if (!ConnectionLost(status))
     {
         GameStateLog.Info("connect net status:" + status);
         if (status == NetConnectionStatus.Connected)
         {
             TransitTo <Login>();
         }
     }
     else
     {
         GameStateLog.ErrorFormat("connect net status:{0}, reason:{1}", status, reason);
         TransitTo <Error>(reason);
     }
 }
Exemplo n.º 6
0
        public override void Start()
        {
            InputManager.Instance.Initialize();
            GameStateLog.Info("Init Input");
            SyncManagerClient.Instance.Initialize();
            GameStateLog.Info("Init SyncManagerClient");
            PlayerManagerClient.Instance.Initialize();
            GameStateLog.Info("Init PlayerManagerClient");

            SimpleUI.Login login = UI.Instance.Show <SimpleUI.Login>();
            login.onJoinGame = (host, port, name) =>
            {
                game.serverHost = host;
                game.serverPort = port;
                game.playerName = name;
                TransitTo <Connect>();
            };
        }
Exemplo n.º 7
0
 void OnNetStatusChanged(UdpConnector netlayer, NetConnectionStatus status, string reason)
 {
     GameStateLog.Info("reconnect net status:" + status);
 }