public void SetPlayerWaitMsg(UserGameState _state, GIPEndPoint _players) { SetPlayerWaitMsg(_state, new List <GIPEndPoint> () { _players }); }
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 { } }
public void Send_2_1(GIPEndPoint _ip) { ByteBuffer buff = new ByteBuffer(); User user = GlobalData.GetUser(_ip); buff.WriteString(user.ToJson()); SendMsg(2, 1, buff); }
public static User GetUser(GIPEndPoint _ip) { try { return(allUser[_ip]); } catch (System.Exception ex) { throw new Exception($"找不到玩家!ip:{_ip} {ex.Message}"); } }
public static Client GetClient(GIPEndPoint _ip) { try { return(allClient[_ip]); } catch (System.Exception ex) { throw new Exception($"找不到客户端!ip:{_ip} {ex.Message}"); } }
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); }
/// <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); } }