Ejemplo n.º 1
0
 public void SetPlayerWaitMsg(UserGameState _state, GIPEndPoint _players)
 {
     SetPlayerWaitMsg(_state, new List <GIPEndPoint> ()
     {
         _players
     });
 }
Ejemplo n.º 2
0
        public void OnSocketConnect(Socket socket, GIPEndPoint point)
        {
            Console.WriteLine($"{point.ToString()} connection!");

            if (!GlobalData.allUser.ContainsKey(point))
            {
                GlobalData.allUser.Add(point, new User()
                {
                    info = new UserInfo()
                    {
                        name = "66666666999999"
                    }
                });
            }

            if (!allClient.ContainsKey(point))
            {
                allClient.Add(point, new Client()
                {
                    socket = socket
                });
                ByteBuffer b = new ByteBuffer();
                b.WriteString($"{point.ToString()} 加入了 !");
                MessageManage.Self.SendMsg(1, 1, b);
            }
            else
            {
            }
        }
Ejemplo n.º 3
0
        public void Send_2_1(GIPEndPoint _ip)
        {
            ByteBuffer buff = new ByteBuffer();
            User       user = GlobalData.GetUser(_ip);

            buff.WriteString(user.ToJson());
            SendMsg(2, 1, buff);
        }
Ejemplo n.º 4
0
 public static User GetUser(GIPEndPoint _ip)
 {
     try {
         return(allUser[_ip]);
     } catch (System.Exception ex) {
         throw new Exception($"找不到玩家!ip:{_ip} {ex.Message}");
     }
 }
Ejemplo n.º 5
0
 public static Client GetClient(GIPEndPoint _ip)
 {
     try
     {
         return(allClient[_ip]);
     }
     catch (System.Exception ex)
     {
         throw new Exception($"找不到客户端!ip:{_ip} {ex.Message}");
     }
 }
Ejemplo n.º 6
0
 public override bool Equals(object obj)
 {
     if (obj.GetType() == typeof(EndPoint) || obj.GetType() == typeof(IPEndPoint))
     {
         IPEndPoint point = obj as IPEndPoint;
         return(point.Address.ToString() == ip && port == point.Port);
     }
     else if (obj.GetType() == typeof(GIPEndPoint))
     {
         GIPEndPoint point = obj as GIPEndPoint;
         return(point.ip == ip && port == point.port);
     }
     return(false);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 监听客户端连接
        /// </summary>
        private void ListenSocketConnect()
        {
            while (true)
            {
                Socket      socket = serverSocket.Accept();
                GIPEndPoint point  = socket.RemoteEndPoint;

                if (OnClientConnent != null)
                {
                    OnSocketConnect(socket, point);
                    OnClientConnent(socket, point);
                }

                Thread receiveThread = new Thread(ReceiveMessage);
                receiveThread.Start(socket);
                threadList.Add(receiveThread);
            }
        }