예제 #1
0
        void OnJoinLobby(JoinLobbyPackage dp)
        {
            if (dp.LobbyId != LobbyId)
                return;

            TcpClient clientToRemove = null;
            foreach (var v in Members)
            {
                if (dp.SenderRemoteIPEndpoint.Address.ToString() == ((IPEndPoint)v.Key.Client.RemoteEndPoint).Address.ToString())
                {
                    clientToRemove = v.Key;
                    break;
                }
            }
            if (clientToRemove != null)
            {
                Members.Remove(clientToRemove);
                Console.WriteLine("Removed " + ((IPEndPoint)clientToRemove.Client.RemoteEndPoint).ToString() + " because joining " +
                    dp.SenderRemoteIPEndpoint.ToString());
            }

            Members.Add(dp.SenderTcpClient, false);

            ResponsePackage rp = new ResponsePackage();
            rp.ResponseId = dp.Id;
            rp.ResponseMessage = (!freeze).ToString();
            Server.Instance.Client.Write(dp.SenderTcpClient, rp);

            UpdateClients();

            Console.WriteLine(dp.SenderRemoteIPEndpoint.ToString() + " joined lobby " + LobbyId);
        }
예제 #2
0
        public override DataPackage CreateFromBody(string b)
        {
            JoinLobbyPackage jlp = new JoinLobbyPackage();

            jlp.LobbyId = int.Parse(b);
            return(jlp);
        }
예제 #3
0
        void OnJoinLobby(JoinLobbyPackage dp)
        {
            if (dp.LobbyId != LobbyId)
            {
                return;
            }

            TcpClient clientToRemove = null;

            foreach (var v in Members)
            {
                if (dp.SenderRemoteIPEndpoint.Address.ToString() == ((IPEndPoint)v.Key.Client.RemoteEndPoint).Address.ToString())
                {
                    clientToRemove = v.Key;
                    break;
                }
            }
            if (clientToRemove != null)
            {
                Members.Remove(clientToRemove);
                Console.WriteLine("Removed " + ((IPEndPoint)clientToRemove.Client.RemoteEndPoint).ToString() + " because joining " +
                                  dp.SenderRemoteIPEndpoint.ToString());
            }

            Members.Add(dp.SenderTcpClient, false);

            ResponsePackage rp = new ResponsePackage();

            rp.ResponseId      = dp.Id;
            rp.ResponseMessage = (!freeze).ToString();
            Server.Instance.Client.Write(dp.SenderTcpClient, rp);

            UpdateClients();

            Console.WriteLine(dp.SenderRemoteIPEndpoint.ToString() + " joined lobby " + LobbyId);
        }
예제 #4
0
    void JoinLobby(Lobby l, Action <bool> onReceive)
    {
        WaitForResponse(JoinLobbyPackage.factory.Id,
                        x =>
        {
            bool success = false;
            bool.TryParse(x.ResponseMessage, out success);

            if (success)
            {
                currentLobby = l;
            }

            if (onReceive != null)
            {
                onReceive(success);
            }
        });

        JoinLobbyPackage jlp = new JoinLobbyPackage();

        jlp.LobbyId = GetLobbyId(l);
        c2s.WriteAll(jlp);
    }
예제 #5
0
    void JoinLobby(Lobby l, Action<bool> onReceive)
    {
        WaitForResponse(JoinLobbyPackage.factory.Id,
        x =>
        {
            bool success = false;
            bool.TryParse(x.ResponseMessage, out success);

            if (success)
                currentLobby = l;

            if (onReceive != null)
                onReceive(success);
        });

        JoinLobbyPackage jlp = new JoinLobbyPackage();
        jlp.LobbyId = GetLobbyId(l);
        c2s.WriteAll(jlp);
    }
예제 #6
0
 public override DataPackage CreateFromBody(string b)
 {
     JoinLobbyPackage jlp = new JoinLobbyPackage();
     jlp.LobbyId = int.Parse(b);
     return jlp;
 }