private void EmitDisconnect()
    {
        Dictionary <string, string> data = new Dictionary <string, string>();

        data["callback_name"]   = StaticManager.disconnect_packName;
        data["local_player_id"] = myId;
        if (GameServer.instance.serverRunning)
        {
            data["isMasterServer"] = "true";
        }
        else
        {
            data["isMasterServer"] = "false";
        }
        string msg = data["local_player_id"] + ":" + data["isMasterServer"];

        Debug.Log("发送客户端 断开连接消息");

        udpClient.Emit(data["callback_name"], msg);

        //断开连接-客户端接口置空
        if (udpClient != null)
        {
            udpClient.disconnect();
        }
    }
    /// <summary>
    /// 客户端断开连接 通知服务器
    /// Emits the disconnect to server
    /// </summary>
    void EmitDisconnect()
    {
        //hash table <key, value>
        Dictionary <string, string> data = new Dictionary <string, string>();

        //JSON package
        data["callback_name"]   = "disconnect";
        data["local_player_id"] = myId;

        //如果这个客户端的服务器正在运行
        if (TicTacToeServer.instance.serverRunning)
        {
            data["isMasterServer"] = "true";
        }
        else
        {
            data["isMasterServer"] = "false";
        }

        string msg = data["local_player_id"] + ":" + data["isMasterServer"];

        Debug.Log("发送客户端 断开连接消息emit disconnect");

        udpClient.Emit(data["callback_name"], msg);

        //如果这个客户端的服务器正在运行,关闭服务器
        //不知道为啥分开在判断一次,让服务器有个响应过程?
        if (TicTacToeServer.instance.serverRunning)
        {
            TicTacToeServer.instance.CloseServer();
            Debug.Log("本地服务器关闭");
        }

        //断开连接-客户端接口置空
        if (udpClient != null)
        {
            udpClient.disconnect();
        }
    }
Esempio n. 3
0
    void GameOver()
    {
        if (myPlayer)
        {
            //hash table <key, value>
            Dictionary <string, string> data = new Dictionary <string, string>();

            //JSON package
            data["callback_name"] = "disconnect";

            data ["local_player_id"] = local_player_id;

            if (UDPServer.instance.serverRunning)
            {
                data ["isMasterServer"] = "true";
            }
            else
            {
                data ["isMasterServer"] = "false";
            }

            //send the position point to server
            string msg = data["local_player_id"] + ":" + data ["isMasterServer"];

            //Debug.Log ("emit disconnect");

            //we make four attempts of similar sending of preventing the loss of packages
            udpClient.Emit(data["callback_name"], msg);

            udpClient.Emit(data["callback_name"], msg);

            udpClient.Emit(data["callback_name"], msg);

            udpClient.Emit(data["callback_name"], msg);
        }

        if (udpClient != null)
        {
            udpClient.disconnect();
        }
    }