public static void Message(byte[] s, WebSocketWrapper wrapper) { using (BinaryReader b = new BinaryReader(new MemoryStream(s))) { byte id = b.ReadByte(); RecordPacket(id); if (id == 16) //Player Packet { if (_agarWorld != null) { _agarWorld.Read(b); } } else if (id == 32) //Player entry packet { _agarWorld.PlayerId = b.ReadUInt32(); _showPopup = false; } else if (id == 49) //Leaderboard List { _leaderboard = ReadLeaderboard(b); } else if (id == 64) //World size packet { _agarWorld = new World(b.ReadDouble(), b.ReadDouble(), b.ReadDouble(), b.ReadDouble()); _agarWorld.PlayerDied += _agarWorld_PlayerDied; } else { throw new Exception(); } } }
public static void Connect(WebSocketWrapper wrapper) { byte[] handshake = new byte[5]; handshake[0] = 255; handshake.SetUInt32(1, 1); wrapper.SendMessage(handshake); _connected = true; }
public static void ConnectToServer(string IP) { if (_ws != null) { DisposeWorld(); } _ipAddress = string.Format("ws://{0}", IP); Uri serverURI = new Uri(string.Format("ws://{0}", IP)); _ws = new WebSocketWrapper(string.Format("ws://{0}", IP)); _ws.OnConnect(Connect); _ws.OnMessage(Message); _ws.OnDisconnect(Disconnect); _ws.Connect(); }
public static void DisposeWorld() { _connected = false; if (_ws != null) { _ws.Close(); } _ws = null; if (_agarWorld != null) { _agarWorld.PlayerDied -= _agarWorld_PlayerDied; } _agarWorld = null; _showPopup = true; _ipAddress = ""; _leaderboard = new List <LeaderboardPlayer>(); }
public static void Disconnect(WebSocketWrapper wrapper) { DisposeWorld(); _box.Text = "Select a server"; }
public static void Disconnect (WebSocketWrapper wrapper) { DisposeWorld(); _box.Text = "Select a server"; }
public static void DisposeWorld() { _connected = false; if (_ws != null) _ws.Close(); _ws = null; if (_agarWorld != null) _agarWorld.PlayerDied -= _agarWorld_PlayerDied; _agarWorld = null; _showPopup = true; _ipAddress = ""; _leaderboard = new List<LeaderboardPlayer>(); }