예제 #1
0
    void OnClientQuit(QuitGameReq req, Connection conn)
    {
        Server.Disconnect(conn.connId);
        //从dict中移出这个连接
        connDict.Remove(conn.connId);

        if (conn.state == ConnState.InGame)
        {   //游戏玩家-1,并通知其他玩家
            inGameClientPlayerCount--;

            LevelManager lm = UnityHelper.GetLevelManager();
            lm.RemovePlayer(conn.playerId);

            UIManager um = UnityHelper.GetUIManager();
            um.AddScrollMessage(string.Format("{0}离开游戏", conn.playerName));

            Protocol.PlayerQuit quit = new PlayerQuit();
            quit.ids    = new int[1];
            quit.ids[0] = conn.playerId;
            GameMsg msg = new GameMsg(GameMsg.MsgType.PlayerQuit, quit);

            SendToAllClientsInGame(msg, UnityEngine.Networking.QosType.ReliableSequenced);
        }
        else if (conn.state == ConnState.WaitForReady)
        {   //游戏玩家-1,
            inGameClientPlayerCount--;
        }
        else if (conn.state == ConnState.Connected)
        {   //不用做什么
        }
    }
예제 #2
0
    public void SendQuitGame()
    {
        Player p = GlobalVariables.localPlayer;

        if (p != null)
        {
            Protocol.QuitGameReq quit = new QuitGameReq();
            GameMsg msg = new GameMsg(GameMsg.MsgType.QuitGameReq, quit);
            Client.SendMessage(msg, UnityEngine.Networking.QosType.ReliableSequenced);
        }
        else
        {
            Debug.LogError("ClientAgent.SendPlayerState >> local player is null");
        }
    }
예제 #3
0
    void OnDateEvent(GameMsg msg, int connId)
    {
        if (connDict.ContainsKey(connId))
        {
            Connection conn = connDict[connId];
            if (conn == null)
            {  //不应该发生
                Debug.LogError("ServerAgent.OnDateEvent>> connection is null");
                return;
            }
            // 设置conn的lastTime
            conn.lastRecvTime = DateTime.Now;

            if (msg.type == GameMsg.MsgType.JoinGameReq)
            {
                JoinGameReq req = msg.content as JoinGameReq;
                if (req != null)
                {
                    OnJoinGameReq(req, conn);
                }
            }
            else if (msg.type == GameMsg.MsgType.ClientReady)
            {
                ClientReady ready = msg.content as ClientReady;
                if (ready != null)
                {
                    OnClientReady(ready, conn);
                }
            }
            else if (msg.type == GameMsg.MsgType.QuitGameReq)
            {
                QuitGameReq quit = msg.content as QuitGameReq;
                if (quit != null)
                {
                    OnClientQuit(quit, conn);
                }
            }
            else if (msg.type == GameMsg.MsgType.ClientLocalPlayerInfo)
            {
                ClientLocalPlayerInfo state = msg.content as ClientLocalPlayerInfo;
                if (state != null)
                {
                    OnClientLocalState(state, conn);
                }
            }
            else if (msg.type == GameMsg.MsgType.Damage)
            {
                HitPlayer hit = msg.content as HitPlayer;
                if (hit != null)
                {
                    OnDamage(hit, conn);
                }
            }
            else if (msg.type == GameMsg.MsgType.Shoot)
            {
                PlayerShoot shoot = msg.content as PlayerShoot;
                if (shoot != null)
                {
                    OnShoot(shoot, conn);
                }
            }
        }
    }