コード例 #1
0
        private async void ConnectToServer(Dictionary <string, string> obj)
        {
            var client = new EasyClient <MyPackageInfo>();

            client.Initialize(new NoReceiveFilter());
            client.Connected          += OnClientConnected;
            client.NewPackageReceived += OnPackageReceived;
            client.Error  += OnClientError;
            client.Closed += OnClientClosed;
            var connected = await client.ConnectAsync(new IPEndPoint(IPAddress.Parse(obj["IPAddress"]), Convert.ToInt32(obj["Port"])));



            if (connected)
            {
                ClientConnectInfo sci = new ClientConnectInfo
                {
                    ServerAddress = obj["IPAddress"] + ":" + obj["Port"],
                    ServerPort    = Convert.ToInt32(obj["Port"]),
                    LocalEndPoint = client.LocalEndPoint.ToString(),
                    IsConnected   = "已连接"
                };

                ClientConnectInfoList.Add(sci);
                ClientList.Add(client);
            }
            else
            {
                DXMessageBox.Show("连接服务端失败!", "提示");
            }

            Messenger.Default.Unregister <Dictionary <string, string> >(this, "ConnectToServer", ConnectToServer);
        }
 public void FakeConnect(GameServer server, ClientConnectInfo info)
 {
     if (server.IsNullOrDestroy())
     {
         return;
     }
     m_ProcessConnect.FakeConnect(server, info);
 }
    void CreateClientPlayer(NetPeer peer, ClientConnectInfo info)
    {
        var clientPlayer = new ClientPlayer(peer);

        clientPlayer.Logger     = Log;
        clientPlayer.PlayerName = info.PlayerName;
        clientPlayer.TypeUnit   = info.TypeUnit;
        m_ClientPlayer          = clientPlayer;
    }
 public void Connect(ClientConnectInfo info)
 {
     if (m_Client.State != ProcessConnection.None)
     {
         return;
     }
     m_Client.StopAllCoroutines();
     StartConnection(info);
 }
 public void FakeConnect(GameServer server, ClientConnectInfo info)
 {
     if (m_Client.State != ProcessConnection.None)
     {
         return;
     }
     m_Client.StopAllCoroutines();
     m_Client.StartCoroutine(StartFakeConnection(server, info));
 }
        IEnumerator StartFakeConnection(GameServer server, ClientConnectInfo info)
        {
            Log("FakeConnectProcess");
            SetConnectionState(ConnectionState.Start);
            SetConnectionState(ConnectionState.LoadLevel);
            yield return(WaitLoadGameLevel());

            m_Client.CreateClientPlayer(null, info);
            server.AddFakeClient(m_Client.m_ClientPlayer);
            SetConnectionState(ConnectionState.End);
            m_Client.CallConnectEvents(new Args()
            {
                Event = ProcessConnection.Connected
            });
        }
    void ClientConnect(ClientConnectInfo info)
    {
        var client = GameClient.I;

        if (client.IsNullOrDestroy())
        {
            BadGameClient("Client does not exist.");
            return;
        }
        //if(client.State != GameClient.ProcessConnection.None)
        //{
        //    client.State = GameClient.ProcessConnection.None;
        //}
        client.ConnectEvents -= OnClientConnectEvents;
        client.ConnectEvents += OnClientConnectEvents;
        client.Connect(info);
    }
    void ServerConnectWithFakeClient(ClientConnectInfo info)
    {
        if (!ServerConnect(info.Port))
        {
            return;
        }
        var client = GameClient.I;

        if (client.IsNullOrDestroy())
        {
            BadGameClient("Client does not exist. F*****g develop's bug.");
            return;
        }
        client.ConnectEvents -= OnClientConnectEvents;
        client.ConnectEvents += OnClientConnectEvents;
        client.FakeConnect(GameServer.I, info);
    }
        void StartConnection(ClientConnectInfo info)
        {
            var manager = m_Client.m_ClientManager;

            if (!manager.IsRunning)
            {
                if (!manager.Start())
                {
                    SendErrorEvent("Client is not running. Look logs.");
                    return;
                }
            }
            var peer = manager.Connect(info.IP, info.Port, GameServer.SERVER_KEY);

            if (peer == null)
            {
                SendErrorEvent("Client connect is bad. Look logs.");
                return;
            }
            m_Client.CreateClientPlayer(peer, info);
            StartProcessConnection();
        }
 public void Connect(ClientConnectInfo info)
 {
     m_ProcessConnect.Connect(info);
 }