示例#1
0
        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();
                }
            }
        }
示例#2
0
        public static void Connect(WebSocketWrapper wrapper)
        {
            byte[] handshake = new byte[5];
            handshake[0] = 255;
            handshake.SetUInt32(1, 1);

            wrapper.SendMessage(handshake);

            _connected = true;
        }
示例#3
0
        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();
        }
示例#4
0
        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>();
        }
示例#5
0
 public static void Disconnect(WebSocketWrapper wrapper)
 {
     DisposeWorld();
     _box.Text = "Select a server";
 }
示例#6
0
        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();
                }
            }
        }
示例#7
0
        public static void Connect(WebSocketWrapper wrapper)
        {
            byte[] handshake = new byte[5];
            handshake[0] = 255;
            handshake.SetUInt32(1, 1);

            wrapper.SendMessage(handshake);

            _connected = true;
        }
示例#8
0
 public static void Disconnect (WebSocketWrapper wrapper)
 {
     DisposeWorld();
     _box.Text = "Select a server";
 }
示例#9
0
        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>();
        }
示例#10
0
        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();
        }