Ejemplo n.º 1
0
        private static void onStatus(HttpListenerContext ctx)
        {
            dynamic status = new ExpandoObject();

            status.status      = "ok";
            status.playercount = RiceServer.GetPlayers().Length;

            var servers = new [] { RiceServer.Auth, RiceServer.Lobby, RiceServer.Game, RiceServer.Area, RiceServer.Ranking };

            status.servers = servers
                             .Select(server => new
            {
                name        = server.Name,
                clientcount = server.GetClients().Length
            });

            status.areas = RiceServer.GetAreas()
                           .Where(a => a.GetPlayerCount() > 0)
                           .Select(area => new
            {
                id          = area.ID,
                playercount = area.GetPlayerCount(),
                players     = area.GetPlayers()
                              .Select(p => new
                {
                    name  = p.ActiveCharacter.Name,
                    level = p.ActiveCharacter.Level
                })
            });

            writeJsonResp(status, ctx);
        }
Ejemplo n.º 2
0
        public static void PlayerInfoReq(RicePacket packet)
        {
            var reqCnt = packet.Reader.ReadUInt32();
            var serial = packet.Reader.ReadUInt16(); // No known scenarios where the requested info count is > 1

            // Followed by the session age of the player we are requesting info for. nplutowhy.avi

            foreach (var p in RiceServer.GetPlayers())
            {
                if (p.ActiveCharacter != null && p.ActiveCharacter.CarSerial == serial)
                {
                    var character  = p.ActiveCharacter;
                    var playerInfo = new Structures.PlayerInfo()
                    {
                        Name   = character.Name,
                        Serial = character.CarSerial,
                        Age    = 0
                    };
                    var res = new RicePacket(802);
                    res.Writer.Write(1);
                    res.Writer.Write(playerInfo);
                    packet.Sender.Send(res);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public static void CheckInGame(RicePacket packet)
        {
            Log.WriteLine("CheckInGame");
            var version  = packet.Reader.ReadUInt32();
            var ticket   = packet.Reader.ReadUInt32();
            var username = packet.Reader.ReadUnicodeStatic(32);
            // Followed by int m_IsPcBang, 21 bytes of weird shit we don't know about, and yet another 21 byte chunk of weird shit we don't know about.

            var serverTicket = RiceServer.GetTicket(ticket);

            if (serverTicket == null || !serverTicket.ValidateOrigin(packet.Sender, username))
            {
                Log.WriteLine("Ticket is non-existent or invalid for current user.");
                Log.WriteLine("ticket: {0}, packet sender: {1}, username: {2}", serverTicket.Identifier, packet.Sender.GetRemoteIP(), username);
                packet.Sender.Error("water u even doin");
                return;
            }

            packet.Sender.Player            = serverTicket.GetOwner();
            packet.Sender.Player.GameClient = packet.Sender;

            var ack = new RicePacket(121);

            ack.Writer.Write(1L);
            packet.Sender.Send(ack);
        }
Ejemplo n.º 4
0
        public static void AreaStatus(RicePacket packet)
        {
            var ack = new RicePacket(0x2AB);

            // from ZoneServer
            for (int i = 0; i < 100; i++)
            {
                var area = RiceServer.GetArea(i);
                ack.Writer.Write(area != null ? area.GetPlayerCount() : 0);
            }
        }
Ejemplo n.º 5
0
        public static void JoinChannel(RicePacket packet)
        {
            var serial = RiceServer.CreateSerial(packet.Sender);

            var ack = new RicePacket(126);

            ack.Writer.WriteUnicodeStatic("speeding", 10);
            ack.Writer.WriteUnicodeStatic(packet.Sender.Player.ActiveCharacter.Name, 16);
            ack.Writer.Write(serial.Identifier);
            ack.Writer.Write((ushort)123); // Age
            packet.Sender.Send(ack);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.Title = "Rice";
            Console.Clear();

            Config config = Config.Load();

            Database.Initialize(config);
            RiceServer.Initialize(config);

            Database.Start();
            RiceServer.Start();

            Console.ReadLine();
        }
Ejemplo n.º 7
0
        public static void CheckInLobby(RicePacket packet)
        {
            Log.WriteLine("CheckInLobby request.");

            uint   version      = packet.Reader.ReadUInt32();
            uint   ticket       = packet.Reader.ReadUInt32();
            string username     = packet.Reader.ReadUnicodeStatic(0x28);
            uint   time         = packet.Reader.ReadUInt32();
            string stringTicket = packet.Reader.ReadASCIIStatic(0x40);

#if DEBUG
            packet.Sender.Player = new Player(Rice.Game.User.Retrieve("admin"));
#else
            foreach (var p in RiceServer.GetPlayers())
            {
                if (p.User.Username == username && p.Ticket == ticket)
                {
                    player             = p;
                    player.LobbyClient = packet.Sender;
                    break;
                }
            }
#endif

            if (packet.Sender.Player == null)
            {
                Log.WriteLine("Rejecting {0} (ticket {1}) for invalid user-ticket combination.", username, ticket);
                packet.Sender.Error("Invalid ticket-user combination.");
                return;
            }

            var ack = new RicePacket(42); // CheckInLobbyAck
            ack.Writer.Write(0);          // Result
            ack.Writer.Write(0);          // Permission
            packet.Sender.Send(ack);

            var timeAck = new RicePacket(47); // LobbyTimeAck
            timeAck.Writer.Write(Environment.TickCount);
            timeAck.Writer.Write(Environment.TickCount);
            packet.Sender.Send(timeAck);

            Log.WriteLine("User {0} entered lobby.", username);
        }
Ejemplo n.º 8
0
        public static void CheckInLobby(RicePacket packet)
        {
            Log.WriteLine("CheckInLobby request.");

            uint   version      = packet.Reader.ReadUInt32();
            uint   ticket       = packet.Reader.ReadUInt32();
            string username     = packet.Reader.ReadUnicodeStatic(0x28);
            uint   time         = packet.Reader.ReadUInt32();
            string stringTicket = packet.Reader.ReadASCIIStatic(0x40);

            var serverTicket = RiceServer.GetTicket(ticket);

            if (serverTicket == null || !serverTicket.ValidateOrigin(packet.Sender, username))
            {
#if DEBUG
                packet.Sender.Player = new Player(Rice.Game.User.Retrieve(username));
                RiceServer.AddPlayer(packet.Sender.Player);
                serverTicket = RiceServer.CreateDebugTicket(packet.Sender, ticket);
#else
                Log.WriteLine("Ticket is non-existent or invalid for current user.");
                packet.Sender.Error("water u even doin");
                return;
#endif
            }
            else
            {
                packet.Sender.Player = serverTicket.GetOwner();
            }


            var ack = new RicePacket(42); // CheckInLobbyAck
            ack.Writer.Write(ticket);     // Ticket
            ack.Writer.Write(0);          // Permission ???
            packet.Sender.Send(ack);

            var timeAck = new RicePacket(47); // LobbyTimeAck
            timeAck.Writer.Write(Environment.TickCount);
            timeAck.Writer.Write(Environment.TickCount);
            packet.Sender.Send(timeAck);

            Log.WriteLine("User {0} entered lobby.", username);
        }
Ejemplo n.º 9
0
        public static void EnterArea(RicePacket packet)
        {
            //TODO: Associate instance with gameserver player based on provided serial, verify, handle
            var serial    = packet.Reader.ReadUInt16();
            var name      = packet.Reader.ReadUnicodeStatic(21);
            var area      = packet.Reader.ReadInt32();
            var group     = packet.Reader.ReadInt32();
            var localtime = packet.Reader.ReadInt32();

            if (packet.Sender.Player == null)
            {
                var serverSerial = RiceServer.GetSerial(serial);

                if (serverSerial == null || serverSerial.GetOwner().ActiveCharacter.Name != name)
                {
                    Log.WriteLine("Serial non-existent or invalid for current user.");
                    packet.Sender.Error("water u even doin");
                    return;
                }

                packet.Sender.Player = serverSerial.GetOwner();
                packet.Sender.Player.ActiveCharacter.CarSerial = serial;
                packet.Sender.Player.AreaClient = packet.Sender;
            }

            RiceServer.GetArea(area).AddPlayer(packet.Sender.Player);

            var ack = new RicePacket(563);

            ack.Writer.Write(area);
            ack.Writer.Write(1); //Result
            ack.Writer.Write(localtime);
            ack.Writer.Write(Environment.TickCount);
            ack.Writer.Write(new byte[6]); // The rest of this is null
            packet.Sender.Send(ack);
        }
Ejemplo n.º 10
0
        public static void ExitArea(RicePacket packet)
        {
            var area = packet.Reader.ReadInt32();

            RiceServer.GetArea(area).RemovePlayer(packet.Sender.Player);
        }
Ejemplo n.º 11
0
        public static void UserAuth(RicePacket packet)
        {
            packet.Reader.ReadInt32(); // Skip 4 bytes.
            var username = packet.Reader.ReadUnicodeStatic(40);
            var password = packet.Reader.ReadASCII();

            string pwhash = Utilities.MD5(password.Substring(0, password.Length - 1));

            User user = User.Retrieve(username, pwhash);

            if (user == null || user.Status == UserStatus.Invalid)
            {
                Log.WriteLine("Attempt to log into non-existant account or use invalid password.");

                var invalid = new RicePacket(22);

                invalid.Writer.Write(0);
                invalid.Writer.Write(1);
                invalid.Writer.Write(new byte[68]);

                packet.Sender.Send(invalid);
                return;
            }
            else if (user.Status == UserStatus.Banned)
            {
                Log.WriteLine("Attempt to log into suspended account {0}.", user.Name);

                packet.Sender.Error("Your account has been suspended.");
                packet.Sender.Kill();
                return;
            }

            Player player = new Player(user);

            player.AuthClient = packet.Sender;
            player.Ticket     = RiceServer.CreateTicket();
            RiceServer.AddPlayer(player);

            var ack = new RicePacket(22);

            ack.Writer.Write(player.Ticket);                         // Ticket
            ack.Writer.Write(0);                                     // Auth Result

            ack.Writer.Write(Environment.TickCount);                 // Time
            ack.Writer.Write(new byte[64]);                          // Filler ("STicket")

            ack.Writer.Write((ushort)23);                            // ServerList ID
            ack.Writer.Write(1);                                     // Server Count

            ack.Writer.WriteUnicodeStatic("Rice Emulator", 32);      // Server Name
            ack.Writer.Write(1);                                     // Server ID

            ack.Writer.Write((float)RiceServer.GetPlayers().Length); // Player Count
            ack.Writer.Write(7000f);                                 // Max Player Count

            ack.Writer.Write(1);                                     // Server State

            ack.Writer.Write(Environment.TickCount);                 // Game Update Time
            ack.Writer.Write(Environment.TickCount);                 // Lobby Update Time
            ack.Writer.Write(Environment.TickCount);                 // Area1 Update Time
            ack.Writer.Write(Environment.TickCount);                 // Area2 Update Time
            ack.Writer.Write(Environment.TickCount);                 // Ranking Update Time

            byte[] ip = IPAddress.Parse(RiceServer.Config.PublicIP).GetAddressBytes();
            ack.Writer.Write(ip);                            // GameServer IP
            ack.Writer.Write(ip);                            // LobbyServer IP
            ack.Writer.Write(ip);                            // AreaServer 1 IP
            ack.Writer.Write(ip);                            // AreaServer 2 IP
            ack.Writer.Write(ip);                            // Ranking IP

            ack.Writer.Write(RiceServer.Config.GamePort);    // GameServer Port
            ack.Writer.Write(RiceServer.Config.LobbyPort);   // LobbyServer Port
            ack.Writer.Write(RiceServer.Config.AreaPort);    // AreaServer 1 Port
            ack.Writer.Write((ushort)11041);                 // AreaServer 2 Port
            ack.Writer.Write((ushort)10701);                 // AreaServer 1 UDP Port
            ack.Writer.Write((ushort)10702);                 // AreaServer 2 UDP Port
            ack.Writer.Write(RiceServer.Config.RankingPort); // Ranking Port

            ack.Writer.Write((ushort)0);                     // what

            packet.Sender.Send(ack);
        }