Esempio n. 1
0
        public void Redirect(Redirect redirect)
        {
            Logger.InfoFormat("Processing redirect");
            GlobalConnectionManifest.RegisterRedirect(this, redirect);
            Logger.InfoFormat("Redirect: cid {0}", this.ConnectionId);
            //GlobalConnectionManifest.DeregisterClient(this);

            redirect.Destination.ExpectedConnections.TryAdd(redirect.Id, redirect);

            var endPoint = Socket.RemoteEndPoint as IPEndPoint;

            byte[] addressBytes = IPAddress.IsLoopback(endPoint.Address) ? IPAddress.Loopback.GetAddressBytes() : Game.IpAddress.GetAddressBytes();

            Array.Reverse(addressBytes);

            var x03 = new ServerPacket(0x03);

            x03.Write(addressBytes);
            x03.WriteUInt16((ushort)redirect.Destination.Port);
            x03.WriteByte((byte)(redirect.EncryptionKey.Length + Encoding.GetEncoding(949).GetBytes(redirect.Name).Length + 7));
            x03.WriteByte(redirect.EncryptionSeed);
            x03.WriteByte((byte)redirect.EncryptionKey.Length);
            x03.Write(redirect.EncryptionKey);
            x03.WriteString8(redirect.Name);
            x03.WriteUInt32(redirect.Id);
            Thread.Sleep(100);
            Enqueue(x03);
        }
Esempio n. 2
0
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name     = packet.ReadString8();
            var password = packet.ReadString8();

            GameLog.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            if (!World.PlayerExists(name))
            {
                client.LoginMessage("That character does not exist", 3);
                GameLog.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
                return;
            }

            if (World.TryGetUser(name, out User loginUser))
            {
                if (loginUser.VerifyPassword(password))
                {
                    GameLog.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                    if (Game.World.WorldData.ContainsKey <User>(name))
                    {
                        GameLog.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                           client.ConnectionId, name);
                        client.LoginMessage("That character is already online. Please try again.", 3);
                        World.ControlMessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                        return;
                    }

                    GameLog.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                    client.LoginMessage("\0", 0);
                    client.SendMessage("Welcome to Hybrasyl!", 3);
                    GameLog.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                    var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                                                client.EncryptionKey);
                    GameLog.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                                       client.ConnectionId, name);
                    loginUser.Login.LastLogin     = DateTime.Now;
                    loginUser.Login.LastLoginFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                    loginUser.Save();
                    client.Redirect(redirect);
                }
                else
                {
                    GameLog.WarningFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                    client.LoginMessage("Incorrect password", 3);
                    loginUser.Login.LastLoginFailure = DateTime.Now;
                    loginUser.Login.LoginFailureCount++;
                    loginUser.Save();
                }
            }
            else
            {
                // Something bad has happened
                client.LoginMessage("An unknown error occurred. Please contact Hybrasyl support.", 3);
            }
        }
Esempio n. 3
0
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name     = packet.ReadString8();
            var password = packet.ReadString8();

            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            User loginUser;

            if (!World.TryGetUser(name, out loginUser))
            {
                client.LoginMessage("That character does not exist", 3);
                Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
            }
            else if (loginUser.VerifyPassword(password))
            {
                Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                if (Game.World.ActiveUsersByName.ContainsKey(name))
                {
                    Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                      client.ConnectionId, name);
                    World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                }

                Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                client.LoginMessage("\0", 0);
                client.SendMessage("Welcome to Hybrasyl!", 3);
                Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                                            client.EncryptionKey);
                Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                                  client.ConnectionId, name);
                client.Redirect(redirect);
                loginUser.Login.LastLogin     = DateTime.Now;
                loginUser.Login.LastLoginFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                loginUser.Save();
            }
            else
            {
                Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                client.LoginMessage("Incorrect password", 3);
                loginUser.Login.LastLoginFailure = DateTime.Now;
                loginUser.Login.LoginFailureCount++;
                loginUser.Save();
            }
        }
Esempio n. 4
0
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name     = packet.ReadString8();
            var password = packet.ReadString8();

            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            using (var ctx = new hybrasylEntities(Constants.ConnectionString))
            {
                var result = ctx.players.Where(player => player.name == name).SingleOrDefault();

                if (result == null)
                {
                    client.LoginMessage("That character does not exist", 3);
                    Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
                }
                else
                {
                    if (VerifyPassword(password, result))
                    {
                        Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                        if (Game.World.ActiveUsersByName.ContainsKey(name))
                        {
                            Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                              client.ConnectionId, name);
                            World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                        }

                        Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                        client.LoginMessage("\0", 0);
                        client.SendMessage("Welcome to Hybrasyl!", 3);
                        Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                        var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                                                    client.EncryptionKey);
                        Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                                          client.ConnectionId, name);
                        client.Redirect(redirect);
                    }
                    else
                    {
                        Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                        client.LoginMessage("Incorrect password", 3);
                    }
                }
            }
        }
Esempio n. 5
0
        private void PacketHandler_0x57_ServerTable(Client client, ClientPacket packet)
        {
            var mismatch = packet.ReadByte();

            if (mismatch == 1)
            {
                var x56 = new ServerPacket(0x56);
                x56.WriteUInt16((ushort)Game.ServerTable.Length);
                x56.Write(Game.ServerTable);
                client.Enqueue(x56);
            }
            else
            {
                var server   = packet.ReadByte();
                var redirect = new Redirect(client, this, Game.Login, "socket", client.EncryptionSeed, client.EncryptionKey);
                client.Redirect(redirect);
            }
        }
Esempio n. 6
0
        private void PacketHandler_0x57_ServerTable(Client client, ClientPacket packet)
        {
            var mismatch = packet.ReadByte();

            if (mismatch == 1)
            {
                var x56 = new ServerPacket(0x56);
                x56.WriteUInt16((ushort)Game.ServerTable.Length);
                x56.Write(Game.ServerTable);
                Logger.InfoFormat("ServerTable: Sent: {0}", BitConverter.ToString(x56.ToArray()));
                client.Enqueue(x56);
            }
            else
            {
                var server   = packet.ReadByte();
                var redirect = new Redirect(client, this, Game.Login, "socket", client.EncryptionSeed, client.EncryptionKey);
                client.Redirect(redirect);
            }
        }
Esempio n. 7
0
        public void Redirect(Redirect redirect, bool isLogoff = false, int transmitDelay = 0)
        {
            GameLog.InfoFormat("Processing redirect");
            GlobalConnectionManifest.RegisterRedirect(this, redirect);
            GameLog.InfoFormat("Redirect: cid {0}", this.ConnectionId);
            GameLog.Info($"Redirect EncryptionKey is {Encoding.ASCII.GetString(redirect.EncryptionKey)}");
            if (isLogoff)
            {
                GlobalConnectionManifest.DeregisterClient(this);
            }
            redirect.Destination.ExpectedConnections.TryAdd(redirect.Id, redirect);

            var endPoint = Socket.RemoteEndPoint as IPEndPoint;

            byte[] addressBytes;

            if (Game.RedirectTarget != null)
            {
                addressBytes = Game.RedirectTarget.GetAddressBytes();
            }
            else
            {
                addressBytes = IPAddress.IsLoopback(endPoint.Address) ? IPAddress.Loopback.GetAddressBytes() : Game.IpAddress.GetAddressBytes();
            }

            Array.Reverse(addressBytes);

            var x03 = new ServerPacket(0x03);

            x03.Write(addressBytes);
            x03.WriteUInt16((ushort)redirect.Destination.Port);
            x03.WriteByte((byte)(redirect.EncryptionKey.Length + Encoding.ASCII.GetBytes(redirect.Name).Length + 7));
            x03.WriteByte(redirect.EncryptionSeed);
            x03.WriteByte((byte)redirect.EncryptionKey.Length);
            x03.Write(redirect.EncryptionKey);
            x03.WriteString8(redirect.Name);
            x03.WriteUInt32(redirect.Id);
            x03.TransmitDelay = transmitDelay == 0 ? 250 : transmitDelay;
            Enqueue(x03);
        }
Esempio n. 8
0
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name = packet.ReadString8();
            var password = packet.ReadString8();
            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            User loginUser;

            if (!World.TryGetUser(name, out loginUser))
            {
                client.LoginMessage("That character does not exist", 3);
                Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);

            }
            else if (loginUser.VerifyPassword(password))
            {
                Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                if (Game.World.ActiveUsersByName.ContainsKey(name))
                {
                    Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                        client.ConnectionId, name);
                    World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                }

                Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                client.LoginMessage("\0", 0);
                client.SendMessage("Welcome to Hybrasyl!", 3);
                Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                    client.EncryptionKey);
                Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                    client.ConnectionId, name);
                client.Redirect(redirect);
                loginUser.Login.LastLogin = DateTime.Now;
                loginUser.Login.LastLoginFrom = ((IPEndPoint) client.Socket.RemoteEndPoint).Address.ToString();
                loginUser.Save();
            }
            else
            {
                Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                client.LoginMessage("Incorrect password", 3);
                loginUser.Login.LastLoginFailure = DateTime.Now;
                loginUser.Login.LoginFailureCount++;
                loginUser.Save();
            }
        }
Esempio n. 9
0
        public void Redirect(Redirect redirect)
        {
            Logger.DebugFormat("Processing redirect");
            GlobalConnectionManifest.DeregisterClient(this);

            redirect.Destination.ExpectedConnections.TryAdd(redirect.Id, redirect);

            var endPoint = Socket.RemoteEndPoint as IPEndPoint;

            byte[] addressBytes = IPAddress.IsLoopback(endPoint.Address) ? IPAddress.Loopback.GetAddressBytes() : Game.IpAddress.GetAddressBytes();

            Array.Reverse(addressBytes);

            var x03 = new ServerPacket(0x03);
            x03.Write(addressBytes);
            x03.WriteUInt16((ushort)redirect.Destination.Port);
            x03.WriteByte((byte)(redirect.EncryptionKey.Length + Encoding.GetEncoding(949).GetBytes(redirect.Name).Length + 7));
            x03.WriteByte(redirect.EncryptionSeed);
            x03.WriteByte((byte)redirect.EncryptionKey.Length);
            x03.Write(redirect.EncryptionKey);
            x03.WriteString8(redirect.Name);
            x03.WriteUInt32(redirect.Id);
            Enqueue(x03);
        }
Esempio n. 10
0
 public static bool TryGetRedirect(long cid, out Redirect redirect)
 {
     return(Redirects.TryGetValue(cid, out redirect));
 }
Esempio n. 11
0
 public static void RegisterRedirect(Client client, Redirect redirect)
 {
     Redirects[client.ConnectionId] = redirect;
 }
Esempio n. 12
0
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name = packet.ReadString8();
            var password = packet.ReadString8();
            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            using (var ctx = new hybrasylEntities(Constants.ConnectionString))
            {

                var result = ctx.players.Where(player => player.name == name).SingleOrDefault();

                if (result == null)
                {
                    client.LoginMessage("That character does not exist", 3);
                    Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
                }
                else
                {
                    if (VerifyPassword(password, result))
                    {
                        Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                        if (Game.World.ActiveUsersByName.ContainsKey(name))
                        {
                            Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                client.ConnectionId, name);
                            World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                        }

                        Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                        client.LoginMessage("\0", 0);
                        client.SendMessage("Welcome to Hybrasyl!", 3);
                        Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                        var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                            client.EncryptionKey);
                        Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                            client.ConnectionId, name);
                        client.Redirect(redirect);
                    }
                    else
                    {
                        Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                        client.LoginMessage("Incorrect password", 3);
                    }
                }
            }
        }