void ProcessLoadPacket(LoadPacket pkt)
 {
     character = db.LoadCharacter(account, pkt.CharacterId);
     if (character != null)
     {
         if (character.Dead)
         {
             SendPacket(new svrPackets.FailurePacket()
             {
                 Message = "Character is dead."
             });
         }
         else
         {
             var target = RealmManager.Worlds[targetWorld];
             //Delay to let client load remote texture
             target.Timers.Add(new WorldTimer(500, (w, t) =>
             {
                 SendPacket(new CreateResultPacket()
                 {
                     CharacterID = character.CharacterId,
                     ObjectID    = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                 });
             }));
             stage = ProtocalStage.Ready;
         }
     }
     else
     {
         Player.SendInfo("Failed to Load character.");
         Disconnect();
     }
 }
Exemple #2
0
 void ProcessLoadPacket(LoadPacket pkt)
 {
     Console.WriteLine("Client load packet");
     character = db0.LoadCharacter(account, pkt.CharacterId);
     if (character != null)
     {
         if (character.Dead)
         {
             SendPacket(new svrPackets.FailurePacket()
             {
                 Message = "Character is dead."
             });
         }
         else
         {
             SendPacket(new CreateResultPacket()
             {
                 CharacterID = character.CharacterId,
                 ObjectID    = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
             });
             stage = ProtocalStage.Ready;
         }
     }
     else
     {
         SendPacket(new svrPackets.FailurePacket()
         {
             Message = "Failed to Load character."
         });
     }
 }
        public void Disconnect()
        {
            try
            {
                if (stage == ProtocalStage.Disconnected)
                {
                    return;
                }
                var original = stage;
                stage = ProtocalStage.Disconnected;
                if (account != null)
                {
                    DisconnectFromRealm();
                }
                if (db != null && original != ProtocalStage.Ready)
                {
                    db.Dispose();
                    db = null;
                }
                skt.Close();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.DarkBlue;
//                Console.WriteLine(e);
                Console.WriteLine("Error disconnecting client, check ClientProcessor.cs");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
Exemple #4
0
        private void ProcessHelloPacket(HelloPacket pkt)
        {
            // connect to database
            db      = new Database();
            account = db.Verify(pkt.GUID, pkt.Password);
            ip      = db.CheckIp(skt.RemoteEndPoint.ToString().Split(':')[0]);

            Console.Write(@"Connecting " + ((account == null)? "null":account.Name) +
                          "@" + ip.Address + "... ");

            // check if ok to connect
            string msg;

            if ((msg = OkToConnect(pkt)) != null)
            {
                Console.WriteLine(msg);
                account = null;
                Disconnect();
                return;
            }

            // ok to connect, add client to client list
            RealmManager.Clients.TryAdd(account.AccountId, this);

            // setup client world
            World world = RealmManager.GetWorld(pkt.GameId);

            if (world.Id == -6) //Test World
            {
                (world as Test).LoadJson(pkt.MapInfo);
            }
            else if (world.IsLimbo)
            {
                world = world.GetInstance(this);
            }
            uint seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;

            Random      = new wRandom(seed);
            targetWorld = world.Id;

            // connection successful, send MapInfo packet
            SendPacket(new MapInfoPacket
            {
                Width         = world.Map.Width,
                Height        = world.Map.Height,
                Name          = world.Name,
                Seed          = seed,
                Background    = world.Background,
                AllowTeleport = world.AllowTeleport,
                ShowDisplays  = world.ShowDisplays,
                Music         = world.GetMusic(Random),
                ClientXML     = world.ClientXML,
                ExtraXML      = world.ExtraXML,
                SendMusic     = true
            });
            stage = ProtocalStage.Handshaked;

            Console.WriteLine("Joined " + world.Name + " (" + world.Id + ").");
        }
Exemple #5
0
 public void Disconnect()
 {
     try
     {
         if (Stage == ProtocalStage.Disconnected)
         {
             return;
         }
         ProtocalStage original = Stage;
         Stage = ProtocalStage.Disconnected;
         if (Account != null)
         {
             DisconnectFromRealm();
         }
         skt.Close();
     }
     catch (Exception e)
     {
         log.Error(e);
     }
 }
Exemple #6
0
        void ProcessHelloPacket(HelloPacket pkt)
        {
            Console.WriteLine("Accepting new client...");
            db0 = new Database();
            if ((account = db0.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                //Database.SaveCharacter(account, Database.CreateCharacter(782, 1));
                 //Database.Register(pkt.GUID, pkt.Password, true);

                if (account == null)
                {
                    Console.WriteLine("Account is null");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });

                    return;
                }

            }
            if (db0.isWhitelisted(db0.Verify(pkt.GUID, pkt.Password)) == false)
            {
                Console.WriteLine("Not whitelisted account trying to connect.");
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "You are not whitelisted!"
                });
                //eventual account ban code (assuming you would punish someone for bypassing the webserver and trying to connect throught a proxy or whatever)
                return;
            }
            if (db0.isBanned(db0.Verify(pkt.GUID, pkt.Password)) == true)
            {
                Console.WriteLine("Banned account trying to connect.");
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Your account is banned!"
                });
                //eventual IP ban code (assuming you would punish someone for bypassing the webserver and trying to connect throught a proxy or whatever)
                return;
            }
            Console.WriteLine("Client trying to connect");
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Console.WriteLine("Failed to connect.");
            }
            else
            {
                Console.WriteLine("Client loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Console.WriteLine("Invalid world");
                }
                else
                {
                    Console.WriteLine("Client joined world " + world.Id.ToString());
                    if (world.Id == -6) //Test World
                        (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                    else if (world.IsLimbo)
                        world = world.GetInstance(this);

                    var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                    Random = new wRandom(seed);
                    targetWorld = world.Id;
                    SendPacket(new MapInfoPacket()
                    {
                        Width = world.Map.Width,
                        Height = world.Map.Height,
                        Name = world.Name,
                        Seed = seed,
                        Background = world.Background,
                        AllowTeleport = world.AllowTeleport,
                        ShowDisplays = world.ShowDisplays,
                        ClientXML = world.ClientXML,
                        ExtraXML = world.ExtraXML
                    });
                    stage = ProtocalStage.Handshaked;
                    Console.WriteLine("End of client world packet");
                }
            }
        }
Exemple #7
0
 void Process()
 {
     try
     {
         stage = ProtocalStage.Connected;
         Packet.BeginReadPacket(skt, this, ReceivePacket, Disconnect);
         NWriter wtr = new NWriter(new NetworkStream(skt));
         while (sendLock.WaitOne())
         {
             if (stage == ProtocalStage.Disconnected) break;
             while (pending.Count > 0)
             {
                 Packet pkt = pending.Dequeue();
                 //if (pkt.ID != PacketID.New_Tick &&
                 //    pkt.ID != PacketID.Ping)
                 //    Console.WriteLine(pkt.ID);
                 Packet.WritePacket(wtr, pkt, this);
             }
         }
     }
     catch
     {
         Disconnect();
     }
 }
        private void ProcessLoadPacket(LoadPacket pkt)
        {
            character = db.LoadCharacter(account, pkt.CharacterId);
            if (character != null)
            {
                if (character.Dead)
                    SendPacket(new FailurePacket
                    {
                        Message = "Character is dead."
                    });
                else if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Account in use: " + account.AccountId);
                    Console.ForegroundColor = ConsoleColor.White;
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                }
                else
                {
                    if (account.Bonuses != null)
                        if (account.Bonuses.Count > 0)
                        {
                            var chrEquip = character.Equipment;
                            for (var i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] == -1)
                                {
                                    chrEquip[i] = account.Bonuses.First();
                                    account.Bonuses.Remove(account.Bonuses.First());
                                    SendPacket(new TextPacket
                                    {
                                        Name = "",
                                        BubbleTime = 0,
                                        Stars = -1,
                                        Text = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                    });
                                    if (account.Bonuses.Count == 0)
                                        break;
                                }
                            }
                            db.SetBonuses(account.AccountId, account.Bonuses);
                            character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    else
                    {
                        account.Bonuses = new List<short>();
                    }
                    if (IP.Gifts != null)
                        if (IP.Gifts.Count > 0)
                        {
                            var chrEquip = character.Equipment;
                            for (var i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] == -1)
                                {
                                    chrEquip[i] = IP.Gifts.First();
                                    IP.Gifts.Remove(IP.Gifts.First());
                                    SendPacket(new TextPacket
                                    {
                                        Name = "",
                                        BubbleTime = 0,
                                        Stars = -1,
                                        Text = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                    });
                                    if (IP.Gifts.Count == 0)
                                        break;
                                }
                            }
                            db.SetBonuses(IP.Address, IP.Gifts);
                            character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    else
                    {
                        IP.Gifts = new List<short>();
                    }

                    var target = RealmManager.Worlds[targetWorld];
                    //Delay to let client load remote texture
                    target.Timers.Add(new WorldTimer(2000, (w, t) => SendPacket(new CreateResultPacket
                    {
                        CharacterID = character.CharacterId,
                        ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                    })));
                    stage = ProtocalStage.Ready;
                }
            }
            else
            {
                Player.SendInfo("Failed to Load character.");
                Disconnect();
            }
        }
        private void ProcessHelloPacket(HelloPacket pkt)
        {
            db = new Database();
            //Console.Out.WriteLine(pkt.GUID + ": " + pkt.Password);
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine(@"Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine(@"Account is null!");
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    db.Dispose();
                    return;
                }
                
            }
            if ((ip = db.CheckIp(skt.RemoteEndPoint.ToString().Split(':')[0])) == null)
            {
                Console.WriteLine(@"Error checking IP");
                SendPacket(new FailurePacket
                {
                    Message = "Error with IP."
                });
                Disconnect();
                db.Dispose();
                return;
            }
            Console.WriteLine(@"Client trying to connect!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine(@"Account in use: " + account.AccountId + @" " + account.Name);
                    account = null;
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    db.Dispose();
                    return;
                }
                account = null;
                SendPacket(new FailurePacket
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine(@"Failed to connect.");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(@"Client loading world");
                Console.ForegroundColor = ConsoleColor.White;
                var world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine(@"Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                try
                {
                    Console.WriteLine(@"Client joined world " + world.Id);
                }
                catch
                {
                    Console.WriteLine(@"Error! World is null");
                }
                Console.ForegroundColor = ConsoleColor.White;
                if (world.Id == -6) //Test World
                    (world as Test).LoadJson(pkt.MapInfo);

                else if (world.IsLimbo)
                    world = world.GetInstance(this);
                var seed = (uint) ((long) Environment.TickCount*pkt.GUID.GetHashCode())%uint.MaxValue;
                Random = new wRandom(seed);
                targetWorld = world.Id;
                if (!ConnectedBuildStartsWith(clientVer))
                {
                    SendPacket(new TextPacket
                    {
                        BubbleTime = 1,
                        Stars = -1,
                        Name = "",
                        Text = "Your client is outdated. Visit http://forum.zerorealms.com to get the latest one!"
                    });
                    Disconnect();
                    /*SendPacket(new TextBoxPacket
                    {
                        Button1 = "Okay",
                        Message = "Your client is outdated, Click <font color=\"white\"><b><a href='http://forum.zerorealms.com'>Here</a></b></font> to get the latest one!",
                        Title = "Outdated Client!",
                        Type = "NewClient"
                    });*/
                }
                SendPacket(new MapInfoPacket
                {
                    Width = world.Map.Width,
                    Height = world.Map.Height,
                    Name = world.Name,
                    Seed = seed,
                    Background = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays = world.ShowDisplays,
                    Music = world.GetMusic(Random),
                    ClientXML = world.ClientXML,
                    ExtraXML = world.ExtraXML,

                    SendMusic = ConnectedBuildStartsWith(clientVer)
                });
                stage = ProtocalStage.Handshaked;
            }
        }
        private void ProcessHelloPacket(HelloPacket pkt)
        {
            if (isGuest)
                Disconnect();
            db = new Database();
//            Console.Out.WriteLine(pkt.GUID + ": " + pkt.Password);
//            Console.Out.WriteLine(pkt.GUID + ": " + account.AccountId + @" " + account.Name);
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine(@"Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine(@"Account is null!");
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    return;
                }
            }
            if ((ip = db.CheckIp(skt.RemoteEndPoint.ToString().Split(':')[0])) == null)
            {
                Console.WriteLine(@"Error checking IP");
                SendPacket(new FailurePacket
                {
                    Message = "Error with IP."
                });
                Disconnect();
                return;
            }
            Console.WriteLine(@"Client trying to connect!" + account.AccountId + @" " + account.Name);
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine(@"Account in use: " + account.AccountId + @" " + account.Name);
                    account = null;
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new FailurePacket
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine(@"Failed to connect.");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(@"Client loading world");
                Console.ForegroundColor = ConsoleColor.White;
                var world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid world, Restart your Client."
                    });
                    Disconnect();
                    Console.WriteLine(@"Invalid world");
                }

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(@"Client joined world " + world.Id);
                Console.ForegroundColor = ConsoleColor.White;
                if (world.Id == -6) //Test World
                    (world as Test).LoadJson(pkt.MapInfo);

                else if (world.IsLimbo)
                    world = world.GetInstance(this);
                var seed = (uint) ((long) Environment.TickCount*pkt.GUID.GetHashCode())%uint.MaxValue;
                Random = new wRandom(seed);
                targetWorld = world.Id;
                SendPacket(new MapInfoPacket
                {
                    Width = world.Map.Width,
                    Height = world.Map.Height,
                    Name = world.Name,
                    Seed = seed,
                    Background = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays = world.ShowDisplays,
                    ClientXML = world.ClientXML,
                    ExtraXML = world.ExtraXML
                });
                stage = ProtocalStage.Handshaked;
            }
        }
Exemple #11
0
        public void Disconnect()
        {
            try
            {
                if (stage == ProtocalStage.Disconnected) return;
                var original = stage;
                stage = ProtocalStage.Disconnected;
                if (account != null)
                {

                    DisconnectFromRealm();
                }
                if (db != null && original != ProtocalStage.Ready)
                {
                    db.Dispose();
                    db = null;
                }
                skt.Close();
            }
            catch
            {
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine("Error disconnecting client, check ClientProcessor.cs");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
Exemple #12
0
 public void Disconnect()
 {
     if (stage == ProtocalStage.Disconnected) return;
     var original = stage;
     stage = ProtocalStage.Disconnected;
     if (account != null)
         DisconnectFromRealm();
     if (db != null && original != ProtocalStage.Ready)
     {
         db.Dispose();
         db = null;
     }
     skt.Close();
 }
Exemple #13
0
        int targetWorld = -1;         //-2 = nexus

        void ProcessHelloPacket(HelloPacket pkt)
        {
            if (isGuest)
            {
                Disconnect();
            }
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine("Account is null!");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    return;
                }
            }
            Console.WriteLine("Client is connecting!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId + " " + account.Name);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine(skt.RemoteEndPoint + " to connect.");
                return;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(skt.RemoteEndPoint + " loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine("Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(skt.RemoteEndPoint + " joined world " + world.Id.ToString());
                if (world.Id == -5)                 //Test World
                {
                    (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                }
                else if (world.IsLimbo)
                {
                    world = world.GetInstance(this);
                }
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random      = new wRandom(seed);
                targetWorld = world.Id;
                SendPacket(new MapInfoPacket()
                {
                    Width         = world.Map.Width,
                    Height        = world.Map.Height,
                    Name          = world.Name,
                    Seed          = seed,
                    Background    = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays  = world.ShowDisplays,
                    //Music = world.GetMusic(Random),
                    ClientXML = world.ClientXML,
                    ExtraXML  = world.ExtraXML
                });
                //TODO: Fix this
                if (hasRead)
                {
                    return;
                }
                else
                {
                    SendPacket(new TextBoxPacket
                    {
                        Button1 = "I understand!",
                        Message = "This server is not meant to be played! It is a playground for exploits. Any exploits such as duping, godmode, and anything in between is allowed. Be warned that players may be able to steal your items. :) \n Add zeroehdev on skype to discuss any exploits. \n Your actions, ip, and id are being logged and time stamped.",
                        Title   = "Watch Out!",
                        Type    = "Test"
                    });
                    Console.WriteLine("[" + DateTime.Now + "]" + Account.AccountId + " has connected!");
                    var dir = @"logs";
                    if (!System.IO.Directory.Exists(dir))
                    {
                        System.IO.Directory.CreateDirectory(dir);
                    }
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\IDConnectedLog.txt", true))
                    {
                        writer.WriteLine("[" + DateTime.Now + "]" + Account.AccountId + " has connected!");
                    }
                    hasRead = !hasRead;
                }
                //DDoS client and server 101:
                //while (hasRead == false)
                //{
                //	//hasRead ^= hasRead;
                //	SendPacket(new TextBoxPacket
                //	{
                //		Button1 = "I understand!",
                //		Message =
                //			"This server is not meant to be played, but rather to be exploited. Any exploits such as duping, godmode, and anything else is allowed. Be warned that players may be able to steal your items. :) \n Add zeroehdev on skype to discuss any exploits. \n Your actions, ip, username, and id are being logged and time stamped.",
                //		Title = "Watch Out!",
                //		Type = "Test"
                //	});
                //	//hasRead ^= hasRead;
                //}
                //hasRead = true;
                stage = ProtocalStage.Handshaked;
            }
        }
Exemple #14
0
 public void Disconnect()
 {
     try
     {
         if (Stage == ProtocalStage.Disconnected) return;
         ProtocalStage original = Stage;
         Stage = ProtocalStage.Disconnected;
         if (Account != null)
             DisconnectFromRealm();
         skt.Close();
     }
     catch(Exception e)
     {
         log.Error(e);
     }
 }
 void ProcessLoadPacket(LoadPacket pkt)
 {
     character = db.LoadCharacter(account, pkt.CharacterId);
     if (character != null)
     {
         if (character.Dead)
             SendPacket(new svrPackets.FailurePacket()
             {
                 Message = "Character is dead."
             });
         else
         {
             var target = RealmManager.Worlds[targetWorld];
             target.Timers.Add(new WorldTimer(1, (w, t) =>
             {
                 SendPacket(new CreateResultPacket()
                 {
                     CharacterID = character.CharacterId,
                     ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                 });
             }));
             stage = ProtocalStage.Ready;
         }
     }
     else
     {
         Player.SendInfo("Failed to load character.");
         Disconnect();
     }
 }
Exemple #16
0
        private void ProcessLoadPacket(LoadPacket pkt)
        {
            character = db.LoadCharacter(account, pkt.CharacterId);
            if (character != null)
            {
                if (character.Dead)
                {
                    SendPacket(new FailurePacket
                    {
                        Message = "Character is dead."
                    });
                    Disconnect();
                }
                else if (CheckAccountInUse(account.AccountId))
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("LoadPacket: " + account.Name + ", account in use.");
                    Console.ForegroundColor = ConsoleColor.White;
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                }
                else
                {
                    if (account.Bonuses != null)
                    {
                        if (account.Bonuses.Count > 0)
                        {
                            short[] chrEquip = character.Equipment;
                            for (int i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] == -1)
                                {
                                    chrEquip[i] = account.Bonuses.First();
                                    account.Bonuses.Remove(account.Bonuses.First());
                                    SendPacket(new TextPacket
                                    {
                                        Name       = "",
                                        BubbleTime = 0,
                                        Stars      = -1,
                                        Text       = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                    });
                                    if (account.Bonuses.Count == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            db.SetBonuses(account.AccountId, account.Bonuses);
                            character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        account.Bonuses = new List <short>();
                    }
                    if (IP.Gifts != null)
                    {
                        if (IP.Gifts.Count > 0)
                        {
                            short[] chrEquip = character.Equipment;
                            for (int i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] == -1)
                                {
                                    chrEquip[i] = IP.Gifts.First();
                                    IP.Gifts.Remove(IP.Gifts.First());
                                    SendPacket(new TextPacket
                                    {
                                        Name       = "",
                                        BubbleTime = 0,
                                        Stars      = -1,
                                        Text       = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                    });
                                    if (IP.Gifts.Count == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            db.SetBonuses(IP.Address, IP.Gifts);
                            character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        IP.Gifts = new List <short>();
                    }

                    World target = RealmManager.Worlds[targetWorld];
                    //Delay to let client load remote texture <-- remote textures will be embedded at some point so this isn't necessary

                    /*target.Timers.Add(new WorldTimer(2000, (w, t) => SendPacket(new CreateResultPacket
                     * {
                     *  CharacterID = character.CharacterId,
                     *  ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                     * })));*/
                    // the previous delay was also taken out to fix a null account variable that happens on occation
                    SendPacket(new CreateResultPacket
                    {
                        CharacterID = character.CharacterId,
                        ObjectID    = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                    });
                    stage = ProtocalStage.Ready;
                }
            }
            else
            {
                Player.SendInfo("Failed to Load character.");
                Disconnect();
            }
        }
        void ProcessHelloPacket(HelloPacket pkt)
        {
            Console.WriteLine("hello packet rec.");
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("account not verifyed.");
                account = Database.CreateGuestAccount(pkt.GUID);

                //Database.SaveCharacter(account, Database.CreateCharacter(782, 1));
                 //Database.Register(pkt.GUID, pkt.Password, true);

                if (account == null)
                {
                    Console.WriteLine("no account");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });

                    return;
                }

            }
            Console.WriteLine("trying connect");
            if (!RealmManager.TryConnect(this))
            {
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Console.WriteLine("Failed to connect.");
            }
            else
            {
                Console.WriteLine("loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Console.WriteLine("Invalid world");
                }
                else
                {
                    Console.WriteLine("In world");
                    if (world.Id == -6) //Test World
                        (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                    else if (world.IsLimbo)
                        world = world.GetInstance(this);

                    var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                    Random = new wRandom(seed);
                    targetWorld = world.Id;
                    SendPacket(new MapInfoPacket()
                    {
                        Width = world.Map.Width,
                        Height = world.Map.Height,
                        Name = world.Name,
                        Seed = seed,
                        Background = world.Background,
                        AllowTeleport = world.AllowTeleport,
                        ShowDisplays = world.ShowDisplays,
                        ClientXML = world.ClientXML,
                        ExtraXML = world.ExtraXML
                    });
                    stage = ProtocalStage.Handshaked;
                    Console.WriteLine("end world");
                }
            }
        }
Exemple #18
0
        void ProcessHelloPacket(HelloPacket pkt)
        {
            /*if (!skt.RemoteEndPoint.ToString().StartsWith("127.0.0.1"))
            {
                SendPacket(new TextPacket()
                {
                    BubbleTime = 0,
                    Stars = -1,
                    Name = "*Error*",
                    Text = "You should not be here!"
                });
                Disconnect();
                return;
            }*/

            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                account = Database.Register(pkt.GUID, pkt.Password, true);
                if (account == null)
                {
                    SendFailure("Invalid account.");
                    Disconnect();
                    return;
                }
            }
            if (!Manager.TryConnect(this))
            {
                account = null;
                SendFailure("Failed to connect.");
                Disconnect();
            }
            else
            {
                World world = Manager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendFailure("Invalid world.");
                    Disconnect();
                }
                else
                {
                    if (world.Id == -6) //Test World
                        (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                    else if (world.IsLimbo)
                        world = world.GetInstance(this);

                    var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                    Random = new wRandom(seed);
                    targetWorld = world.Id;
                    SendPacket(new MapInfoPacket()
                    {
                        Width = world.Map.Width,
                        Height = world.Map.Height,
                        Name = world.Name,
                        Seed = seed,
                        Background = world.Background,
                        AllowTeleport = world.AllowTeleport,
                        ShowDisplays = world.ShowDisplays,
                        ClientXML = world.ClientXML,
                        ExtraXML = world.ExtraXML
                    });
                    stage = ProtocalStage.Handshaked;
                }
            }
        }
        private void ProcessHelloPacket(HelloPacket pkt)
        {
            db = new Database();
            //Console.Out.WriteLine(pkt.GUID + ": " + pkt.Password);
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine(@"Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine(@"Account is null!");
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    db.Dispose();
                    return;
                }
            }
            if ((ip = db.CheckIp(skt.RemoteEndPoint.ToString().Split(':')[0])) == null)
            {
                Console.WriteLine(@"Error checking IP");
                SendPacket(new FailurePacket
                {
                    Message = "Error with IP."
                });
                Disconnect();
                db.Dispose();
                return;
            }
            Console.WriteLine(@"Client trying to connect!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine(@"Account in use: " + account.AccountId + @" " + account.Name);
                    account = null;
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    db.Dispose();
                    return;
                }
                account = null;
                SendPacket(new FailurePacket
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine(@"Failed to connect.");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(@"Client loading world");
                Console.ForegroundColor = ConsoleColor.White;
                var world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new FailurePacket
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine(@"Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                try
                {
                    Console.WriteLine(@"Client joined world " + world.Id);
                }
                catch
                {
                    Console.WriteLine(@"Error! World is null");
                }
                Console.ForegroundColor = ConsoleColor.White;
                if (world.Id == -6) //Test World
                {
                    (world as Test).LoadJson(pkt.MapInfo);
                }

                else if (world.IsLimbo)
                {
                    world = world.GetInstance(this);
                }
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random      = new wRandom(seed);
                targetWorld = world.Id;
                if (!ConnectedBuildStartsWith(clientVer))
                {
                    SendPacket(new TextPacket
                    {
                        BubbleTime = 1,
                        Stars      = -1,
                        Name       = "",
                        Text       = "Your client is outdated. Visit http://forum.zerorealms.com to get the latest one!"
                    });
                    Disconnect();

                    /*SendPacket(new TextBoxPacket
                     * {
                     *  Button1 = "Okay",
                     *  Message = "Your client is outdated, Click <font color=\"white\"><b><a href='http://forum.zerorealms.com'>Here</a></b></font> to get the latest one!",
                     *  Title = "Outdated Client!",
                     *  Type = "NewClient"
                     * });*/
                }
                SendPacket(new MapInfoPacket
                {
                    Width         = world.Map.Width,
                    Height        = world.Map.Height,
                    Name          = world.Name,
                    Seed          = seed,
                    Background    = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays  = world.ShowDisplays,
                    Music         = world.GetMusic(Random),
                    ClientXML     = world.ClientXML,
                    ExtraXML      = world.ExtraXML,

                    SendMusic = ConnectedBuildStartsWith(clientVer)
                });
                stage = ProtocalStage.Handshaked;
            }
        }
Exemple #20
0
        void ProcessCreatePacket(CreatePacket pkt)
        {
            int nextCharId = 1;
            nextCharId = db.GetNextCharID(account);
            var cmd = db.CreateQuery();
            cmd.CommandText = "SELECT maxCharSlot FROM accounts WHERE id=@accId;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            int maxChar = (int)cmd.ExecuteScalar();

            cmd = db.CreateQuery();
            cmd.CommandText = "SELECT COUNT(id) FROM characters WHERE accId=@accId AND dead = FALSE;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            int currChar = (int)(long)cmd.ExecuteScalar();

            if (currChar >= maxChar)
            {
                Disconnect();
                return;
            }

            character = Database.CreateCharacter(pkt.ObjectType, nextCharId);

            int[] stats = new int[]
            {
                character.MaxHitPoints,
                character.MaxMagicPoints,
                character.Attack,
                character.Defense,
                character.Speed,
                character.Dexterity,
                character.HpRegen,
                character.MpRegen,
            };

            bool ok = true;
            cmd = db.CreateQuery();
            cmd.CommandText = @"INSERT INTO characters(accId, charId, charType, level, exp, fame, items, hp, mp, stats, dead, pet)
             VALUES(@accId, @charId, @charType, 1, 0, 0, @items, 100, 100, @stats, FALSE, -1);";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            cmd.Parameters.AddWithValue("@charId", nextCharId);
            cmd.Parameters.AddWithValue("@charType", pkt.ObjectType);
            cmd.Parameters.AddWithValue("@items", character._Equipment);
            cmd.Parameters.AddWithValue("@stats", Utils.GetCommaSepString(stats));
            int v = cmd.ExecuteNonQuery();
            ok = v > 0;

            if (ok)
            {
                SendPacket(new CreateSuccessPacket()
                {
                    CharacterID = character.CharacterId,
                    ObjectID = Manager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                });
                stage = ProtocalStage.Ready;
            }
            else
                SendFailure("Failed to Load character.");
        }
        private void ProcessCreatePacket(CreatePacket pkt)
        {
            //          try
            //          {
            var nextCharId = 1;

            nextCharId = db.GetNextCharId(account);
            var cmd = db.CreateQuery();

            cmd.CommandText = "SELECT maxCharSlot FROM accounts WHERE id=@accId;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            var maxChar = (int)cmd.ExecuteScalar();

            cmd             = db.CreateQuery();
            cmd.CommandText = "SELECT COUNT(id) FROM characters WHERE accId=@accId AND dead = FALSE;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            var currChar = (int)(long)cmd.ExecuteScalar();


            if (currChar >= maxChar)
            {
                Disconnect();
                return;
            }
            if (CheckAccountInUse(account.AccountId) != false)
            {
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine(@"Account in use: " + account.AccountId);
                Console.ForegroundColor = ConsoleColor.White;
                SendPacket(new FailurePacket
                {
                    Message = "Account in use! Retrying..."
                });
                return;
            }

            character = Database.CreateCharacter(pkt.ObjectType, nextCharId);


            var stats = new int[]
            {
                character.MaxHitPoints,
                character.MaxMagicPoints,
                character.Attack,
                character.Defense,
                character.Speed,
                character.Dexterity,
                character.HpRegen,
                character.MpRegen,
            };

            var ok = true;

            cmd = db.CreateQuery();
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            cmd.Parameters.AddWithValue("@charId", nextCharId);
            cmd.Parameters.AddWithValue("@charType", pkt.ObjectType);
            cmd.Parameters.AddWithValue("@items", Utils.GetCommaSepString(character.EquipSlots()));
            cmd.Parameters.AddWithValue("@stats", Utils.GetCommaSepString(stats));
            cmd.Parameters.AddWithValue("@fameStats", character.FameStats.ToString());
            cmd.CommandText =
                "INSERT INTO characters (accId, charId, charType, level, exp, fame, items, hp, mp, stats, dead, pet, fameStats) VALUES (@accId, @charId, @charType, 1, 0, 0, @items, 100, 100, @stats, FALSE, -1, @fameStats);";
            var v = cmd.ExecuteNonQuery();

            ok = v > 0;

            if (ok)
            {
                if (account.Bonuses != null)
                {
                    if (account.Bonuses.Count > 0)
                    {
                        var chrEquip = character.Equipment;
                        for (var i = 4; i < 12; i++)
                        {
                            if (chrEquip[i] == -1)
                            {
                                chrEquip[i] = account.Bonuses.First();
                                account.Bonuses.Remove(account.Bonuses.First());
                                SendPacket(new TextPacket
                                {
                                    Name       = "",
                                    BubbleTime = 0,
                                    Stars      = -1,
                                    Text       = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                });
                                if (account.Bonuses.Count == 0)
                                {
                                    break;
                                }
                            }
                        }
                        db.SetBonuses(account.AccountId, account.Bonuses);
                        character.Equipment = chrEquip;
                    }
                    else
                    {
                    }
                }
                else
                {
                    account.Bonuses = new List <short>();
                }
                if (IP.Gifts != null)
                {
                    if (IP.Gifts.Count > 0)
                    {
                        var chrEquip = character.Equipment;
                        for (var i = 4; i < 12; i++)
                        {
                            if (chrEquip[i] == -1)
                            {
                                chrEquip[i] = IP.Gifts.First();
                                IP.Gifts.Remove(IP.Gifts.First());
                                SendPacket(new TextPacket
                                {
                                    Name       = "",
                                    BubbleTime = 0,
                                    Stars      = -1,
                                    Text       = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                });
                                if (IP.Gifts.Count == 0)
                                {
                                    break;
                                }
                            }
                        }
                        db.SetBonuses(IP.Address, IP.Gifts);
                        character.Equipment = chrEquip;
                    }
                    else
                    {
                    }
                }
                else
                {
                    IP.Gifts = new List <short>();
                }
                db.SaveBackpacks(character, account);
            }

            if (ok)
            {
                var target = RealmManager.Worlds[targetWorld];
                //Delay to let client load remote texture
//                target.Timers.Add(new WorldTimer(2000, (w, t) => SendPacket(new CreateResultPacket
                target.Timers.Add(new WorldTimer(500, (w, t) => SendPacket(new CreateResultPacket
                {
                    CharacterID = character.CharacterId,
                    ObjectID    = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                })));
                stage = ProtocalStage.Ready;
            }
            else
            {
                SendPacket(new FailurePacket
                {
                    Message = "Failed to Load character."
                });
            }
            //           }
            //           catch (Exception e) { }
        }
Exemple #22
0
 void ProcessLoadPacket(LoadPacket pkt)
 {
     character = db.LoadCharacter(account, pkt.CharacterId);
     if (character != null)
     {
         if (character.Dead)
             SendFailure("Character is dead.");
         else
         {
             SendPacket(new CreateSuccessPacket()
             {
                 CharacterID = character.CharacterId,
                 ObjectID = Manager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
             });
             stage = ProtocalStage.Ready;
         }
     }
     else
         SendFailure("Failed to Load character.");
 }
        private void ProcessLoadPacket(LoadPacket pkt)
        {
            character = db.LoadCharacter(account, pkt.CharacterId);
            if (character != null)
            {
                if (character.Dead)
                {
                    SendPacket(new FailurePacket
                    {
                        Message = "Character is dead."
                    });
                }
                else if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Account in use: " + account.AccountId);
                    Console.ForegroundColor = ConsoleColor.White;
                    SendPacket(new FailurePacket
                    {
                        Message = "Account in use! Retrying..."
                    });
                }
                else
                {
                    if (account.Bonuses != null)
                    {
                        if (account.Bonuses.Count > 0)
                        {
                            var chrEquip = character.Equipment;
                            for (var i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] == -1)
                                {
                                    chrEquip[i] = account.Bonuses.First();
                                    account.Bonuses.Remove(account.Bonuses.First());
                                    SendPacket(new TextPacket
                                    {
                                        Name       = "",
                                        BubbleTime = 0,
                                        Stars      = -1,
                                        Text       = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                    });
                                    if (account.Bonuses.Count == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            db.SetBonuses(account.AccountId, account.Bonuses);
                            character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        account.Bonuses = new List <short>();
                    }
                    if (IP.Gifts != null)
                    {
                        if (IP.Gifts.Count > 0)
                        {
                            var chrEquip = character.Equipment;
                            for (var i = 4; i < 12; i++)
                            {
                                if (chrEquip[i] == -1)
                                {
                                    chrEquip[i] = IP.Gifts.First();
                                    IP.Gifts.Remove(IP.Gifts.First());
                                    SendPacket(new TextPacket
                                    {
                                        Name       = "",
                                        BubbleTime = 0,
                                        Stars      = -1,
                                        Text       = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                    });
                                    if (IP.Gifts.Count == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            db.SetBonuses(IP.Address, IP.Gifts);
                            character.Equipment = chrEquip;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        IP.Gifts = new List <short>();
                    }

                    var target = RealmManager.Worlds[targetWorld];
                    //Delay to let client load remote texture
//                    target.Timers.Add(new WorldTimer(2000, (w, t) => SendPacket(new CreateResultPacket
                    target.Timers.Add(new WorldTimer(500, (w, t) => SendPacket(new CreateResultPacket
                    {
                        CharacterID = character.CharacterId,
                        ObjectID    = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                    })));
                    stage = ProtocalStage.Ready;
                }
            }
            else
            {
                Player.SendInfo("Failed to Load character.");
                Disconnect();
            }
        }
Exemple #24
0
 void ProcessLoadPacket(LoadPacket pkt)
 {
     character = db.LoadCharacter(account, pkt.CharacterId);
     if (character != null)
     {
         if (character.Dead)
             SendPacket(new svrPackets.FailurePacket()
             {
                 Message = "Character is dead."
             });
         else
         {
             var target = RealmManager.Worlds[targetWorld];
             //Delay to let client load remote texture
             target.Timers.Add(new WorldTimer(500, (w, t) =>
             {
                 SendPacket(new CreateResultPacket()
                 {
                     CharacterID = character.CharacterId,
                     ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                 });
                 w.BroadcastPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Stars = -1,
                     Name = "",
                     Text = account.Name + " has connected."
                 }, entity);
             }));
             stage = ProtocalStage.Ready;
         }
     }
     else
     {
         Player.SendInfo("Failed to Load character.");
         Disconnect();
     }
 }
Exemple #25
0
        void ProcessHelloPacket(HelloPacket pkt)
        {
            if (isGuest)
            {
                Disconnect();
            }
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine("Account is null!");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    return;
                }
            }
            Console.WriteLine("Client trying to connect!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId + " " + account.Name);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine("Failed to connect.");
                return;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Client loading world");
                Console.ForegroundColor = ConsoleColor.White;
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine("Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Client joined world " + world.Id.ToString());
                Console.ForegroundColor = ConsoleColor.White;
                if (world.Id == -6) //Test World
                {
                    (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                }

                else if (world.IsLimbo)
                {
                    world = world.GetInstance(this);
                }
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random      = new wRandom(seed);
                targetWorld = world.Id;
                SendPacket(new MapInfoPacket()
                {
                    Width         = world.Map.Width,
                    Height        = world.Map.Height,
                    Name          = world.Name,
                    Seed          = seed,
                    Background    = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays  = world.ShowDisplays,
                    ClientXML     = world.ClientXML,
                    ExtraXML      = world.ExtraXML
                });
                stage = ProtocalStage.Handshaked;
                if (!Connected)
                {
                    Connected = true;
                }
            }
        }
 public void Disconnect()
 {
     try
     {
         if (stage == ProtocalStage.Disconnected) return;
         var original = stage;
         stage = ProtocalStage.Disconnected;
         if (account != null)
             DisconnectFromRealm();
         if (db != null && original != ProtocalStage.Ready)
         {
             db.Dispose();
             db = null;
         }
         skt.Close();
     }
     catch (Exception e)
     {
         Console.ForegroundColor = ConsoleColor.DarkBlue;
         Console.WriteLine(e);
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
Exemple #27
0
 public void Disconnect()
 {
     try
     {
         if (stage == ProtocalStage.Disconnected) return;
         var original = stage;
         stage = ProtocalStage.Disconnected;
         if (account != null)
             DisconnectFromRealm();
         if (db != null && original != ProtocalStage.Ready)
         {
             db.Dispose();
             db = null;
         }
         skt.Close();
     }
     catch
     {
         logger.Error("Error disconnecting client, check Client.cs");
     }
 }
        private void ProcessCreatePacket(CreatePacket pkt)
        {
            var nextCharId = 1;
            var maxChar = 2;
            nextCharId = db.GetNextCharId(account);
            var cmd = db.CreateQuery();
            cmd.CommandText = "SELECT maxCharSlot FROM accounts WHERE id=@accId;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            try
            {
                maxChar = (int)cmd.ExecuteScalar();
            }
            catch
            {
            }
            cmd = db.CreateQuery();
            cmd.CommandText = "SELECT COUNT(id) FROM characters WHERE accId=@accId AND dead = FALSE;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            var currChar = (int)(long)cmd.ExecuteScalar();

            if (currChar >= maxChar)
            {
                Disconnect();
                db.Dispose();
                return;
            }
            if (CheckAccountInUse(account.AccountId) != false)
            {
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine(@"Account in use: " + account.AccountId);
                Console.ForegroundColor = ConsoleColor.White;
                SendPacket(new FailurePacket
                {
                    Message = "Account in use! Retrying..."
                });
                db.Dispose();
                return;
            }

            character = Database.CreateCharacter(pkt.ObjectType, nextCharId);
            var stats = new int[]
            {
                character.MaxHitPoints,
                character.MaxMagicPoints,
                character.Attack,
                character.Defense,
                character.Speed,
                character.Dexterity,
                character.HpRegen,
                character.MpRegen,
            };

            var ok = true;
            cmd = db.CreateQuery();
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            cmd.Parameters.AddWithValue("@charId", nextCharId);
            cmd.Parameters.AddWithValue("@charType", pkt.ObjectType);
            cmd.Parameters.AddWithValue("@items", Utils.GetCommaSepString(character.EquipSlots()));
            cmd.Parameters.AddWithValue("@stats", Utils.GetCommaSepString(stats));
            cmd.Parameters.AddWithValue("@fameStats", character.FameStats.ToString());
            cmd.CommandText =
                "INSERT INTO characters (accId, charId, charType, level, exp, fame, items, hp, mp, stats, dead, pet, fameStats) VALUES (@accId, @charId, @charType, 1, 0, 0, @items, 100, 100, @stats, FALSE, -1, @fameStats);";
            var v = cmd.ExecuteNonQuery();
            ok = v > 0;

            if (ok)
            {
                if (account.Bonuses != null)
                    if (account.Bonuses.Count > 0)
                    {
                        var chrEquip = character.Equipment;
                        for (var i = 4; i < 12; i++)
                        {
                            if (chrEquip[i] == -1)
                            {
                                chrEquip[i] = account.Bonuses.First();
                                account.Bonuses.Remove(account.Bonuses.First());
                                SendPacket(new TextPacket
                                {
                                    Name = "",
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Text = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                });
                                if (account.Bonuses.Count == 0)
                                    break;
                            }
                        }
                        db.SetBonuses(account.AccountId, account.Bonuses);
                        character.Equipment = chrEquip;
                    }
                    else
                    {
                    }
                else
                {
                    account.Bonuses = new List<short>();
                }
                if (IP.Gifts != null)
                    if (IP.Gifts.Count > 0)
                    {
                        var chrEquip = character.Equipment;
                        for (var i = 4; i < 12; i++)
                        {
                            if (chrEquip[i] == -1)
                            {
                                chrEquip[i] = IP.Gifts.First();
                                IP.Gifts.Remove(IP.Gifts.First());
                                SendPacket(new TextPacket
                                {
                                    Name = "",
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Text = "You received " + XmlDatas.TypeToId[chrEquip[i]] + "."
                                });
                                if (IP.Gifts.Count == 0)
                                    break;
                            }
                        }
                        db.SetBonuses(IP.Address, IP.Gifts);
                        character.Equipment = chrEquip;
                    }
                    else
                    {
                    }
                else
                {
                    IP.Gifts = new List<short>();
                }
                db.SaveBackpacks(character, account);
            }

            if (ok)
            {
                var target = RealmManager.Worlds[targetWorld];
                //Delay to let client load remote texture
                target.Timers.Add(new WorldTimer(2000, (w, t) => SendPacket(new CreateResultPacket
                {
                    CharacterID = character.CharacterId,
                    ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                })));
                stage = ProtocalStage.Ready;
            }
            else
                SendPacket(new FailurePacket
                {
                    Message = "Failed to Load character."
                });
        }
Exemple #29
0
        private void ProcessHelloPacket(HelloPacket pkt)
        {
            if (isGuest)
                Disconnect();
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                logger.Info("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    logger.Info("Account is null!");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    return;
                }
            }
            logger.Info("Client trying to connect!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    logger.Info("Account in use: " + account.AccountId + " " + account.Name);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                logger.Info("Failed to connect.");
                return;
            }
            else
            {
                logger.Warn("Client loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    logger.Error("Invalid world");
                }
                logger.Error("Client joined world " + world.Id.ToString());
                if (world.Id == -6) //Test World
                    (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                else if (world.IsLimbo)
                    world = world.GetInstance(this);
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random = new wRandom(seed);
                targetWorld = world.Id;
                SendPacket(new MapInfoPacket()
                {
                    Width = world.Map.Width,
                    Height = world.Map.Height,
                    Name = world.Name,
                    Seed = seed,
                    Background = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays = world.ShowDisplays,
                    ClientXML = world.ClientXML,
                    ExtraXML = world.ExtraXML
                });
                stage = ProtocalStage.Handshaked;
            }
        }
Exemple #30
0
 public void Disconnect()
 {
     try
     {
         if (stage == ProtocalStage.Disconnected) return;
         var original = stage;
         stage = ProtocalStage.Disconnected;
         if (account != null)
             DisconnectFromRealm();
         if (db0 != null && original != ProtocalStage.Ready)
         {
             db0.Dispose();
             db0 = null;
         }
         skt.Close();
         sendLock.Set();
     }
     catch
     {
         Console.WriteLine("Error disconnecting client, check ClientProcessor.cs");
     }
 }
Exemple #31
0
        void ProcessHelloPacket(HelloPacket pkt)
        {
            Console.WriteLine("Accepting new client...");
            db0 = new Database();
            if ((account = db0.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                //Database.SaveCharacter(account, Database.CreateCharacter(782, 1));
                //Database.Register(pkt.GUID, pkt.Password, true);

                if (account == null)
                {
                    Console.WriteLine("Account is null");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });

                    return;
                }
            }
            if (db0.isWhitelisted(db0.Verify(pkt.GUID, pkt.Password)) == false)
            {
                Console.WriteLine("Not whitelisted account trying to connect.");
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "You are not whitelisted!"
                });
                //eventual account ban code (assuming you would punish someone for bypassing the webserver and trying to connect throught a proxy or whatever)
                return;
            }
            if (db0.isBanned(db0.Verify(pkt.GUID, pkt.Password)) == true)
            {
                Console.WriteLine("Banned account trying to connect.");
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Your account is banned!"
                });
                //eventual IP ban code (assuming you would punish someone for bypassing the webserver and trying to connect throught a proxy or whatever)
                return;
            }
            Console.WriteLine("Client trying to connect");
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Console.WriteLine("Failed to connect.");
            }
            else
            {
                Console.WriteLine("Client loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Console.WriteLine("Invalid world");
                }
                else
                {
                    Console.WriteLine("Client joined world " + world.Id.ToString());
                    if (world.Id == -6) //Test World
                    {
                        (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                    }
                    else if (world.IsLimbo)
                    {
                        world = world.GetInstance(this);
                    }

                    var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                    Random      = new wRandom(seed);
                    targetWorld = world.Id;
                    SendPacket(new MapInfoPacket()
                    {
                        Width         = world.Map.Width,
                        Height        = world.Map.Height,
                        Name          = world.Name,
                        Seed          = seed,
                        Background    = world.Background,
                        AllowTeleport = world.AllowTeleport,
                        ShowDisplays  = world.ShowDisplays,
                        ClientXML     = world.ClientXML,
                        ExtraXML      = world.ExtraXML
                    });
                    stage = ProtocalStage.Handshaked;
                    Console.WriteLine("End of client world packet");
                }
            }
        }
Exemple #32
0
        void ProcessCreatePacket(CreatePacket pkt)
        {
            Console.WriteLine("Client char create packet");
            int nextCharId = 1;
            nextCharId = db0.GetNextCharID(account);
            var cmd = db0.CreateQuery();
            cmd.CommandText = "SELECT maxCharSlot FROM accounts WHERE id=@accId;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            object maxChar1 = cmd.ExecuteScalar();
            int maxChar = int.Parse(maxChar1.ToString());
            cmd = db0.CreateQuery();
            cmd.CommandText = "SELECT COUNT(id) FROM characters WHERE accId=@accId AND dead = FALSE;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            object currChar1 = cmd.ExecuteScalar();
            int currChar = int.Parse(currChar1.ToString());

            if (currChar >= maxChar)
            {
                Disconnect();
            }
            if (CheckAccountInUse(account.AccountId) != false)
            {
                Console.WriteLine("Account in use: " + account.AccountId);
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Account in use! Retrying..."
                });
                return;
            }
            Console.WriteLine("Client second char create packet");

            character = Database.CreateCharacter(pkt.ObjectType, nextCharId);

            int[] stats = new int[]
            {
                character.MaxHitPoints,
                character.MaxMagicPoints,
                character.Attack,
                character.Defense,
                character.Speed,
                character.Dexterity,
                character.HpRegen,
                character.MpRegen,
            };

            bool ok = true;
            cmd = db0.CreateQuery();
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            cmd.Parameters.AddWithValue("@charId", nextCharId);
            cmd.Parameters.AddWithValue("@charType", pkt.ObjectType);
            cmd.Parameters.AddWithValue("@items", character._Equipment);
            cmd.Parameters.AddWithValue("@stats", Utils.GetCommaSepString(stats));
            cmd.Parameters.AddWithValue("@fameStats", character.FameStats.ToString());
            cmd.CommandText = "INSERT INTO characters (accId, charId, charType, level, exp, fame, items, hp, mp, stats, dead, pet, fameStats) VALUES (@accId, @charId, @charType, 1, 0, 0, @items, 100, 100, @stats, FALSE, -1, @fameStats);";
            int v = cmd.ExecuteNonQuery();
            //int v = 1;
            ok = v > 0;

            Console.WriteLine("Client char create packet result: "+ok);

            if (ok)
            {
                SendPacket(new CreateResultPacket()
                {
                    CharacterID = character.CharacterId,
                    ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                });
                stage = ProtocalStage.Ready;
            }
            else
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to Load character."
                });
        }
Exemple #33
0
        void ProcessCreatePacket(CreatePacket pkt)
        {
            Console.WriteLine("Client char create packet");
            int nextCharId = 1;

            nextCharId = db0.GetNextCharID(account);
            var cmd = db0.CreateQuery();

            cmd.CommandText = "SELECT maxCharSlot FROM accounts WHERE id=@accId;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            object maxChar1 = cmd.ExecuteScalar();
            int    maxChar  = int.Parse(maxChar1.ToString());

            cmd             = db0.CreateQuery();
            cmd.CommandText = "SELECT COUNT(id) FROM characters WHERE accId=@accId AND dead = FALSE;";
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            object currChar1 = cmd.ExecuteScalar();
            int    currChar  = int.Parse(currChar1.ToString());

            if (currChar >= maxChar)
            {
                Disconnect();
            }
            if (CheckAccountInUse(account.AccountId) != false)
            {
                Console.WriteLine("Account in use: " + account.AccountId);
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Account in use! Retrying..."
                });
                return;
            }
            Console.WriteLine("Client second char create packet");

            character = Database.CreateCharacter(pkt.ObjectType, nextCharId);

            int[] stats = new int[]
            {
                character.MaxHitPoints,
                character.MaxMagicPoints,
                character.Attack,
                character.Defense,
                character.Speed,
                character.Dexterity,
                character.HpRegen,
                character.MpRegen,
            };

            bool ok = true;

            cmd = db0.CreateQuery();
            cmd.Parameters.AddWithValue("@accId", account.AccountId);
            cmd.Parameters.AddWithValue("@charId", nextCharId);
            cmd.Parameters.AddWithValue("@charType", pkt.ObjectType);
            cmd.Parameters.AddWithValue("@items", character._Equipment);
            cmd.Parameters.AddWithValue("@stats", Utils.GetCommaSepString(stats));
            cmd.Parameters.AddWithValue("@fameStats", character.FameStats.ToString());
            cmd.CommandText = "INSERT INTO characters (accId, charId, charType, level, exp, fame, items, hp, mp, stats, dead, pet, fameStats) VALUES (@accId, @charId, @charType, 1, 0, 0, @items, 100, 100, @stats, FALSE, -1, @fameStats);";
            int v = cmd.ExecuteNonQuery();

            //int v = 1;
            ok = v > 0;

            Console.WriteLine("Client char create packet result: " + ok);

            if (ok)
            {
                SendPacket(new CreateResultPacket()
                {
                    CharacterID = character.CharacterId,
                    ObjectID    = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
                });
                stage = ProtocalStage.Ready;
            }
            else
            {
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to Load character."
                });
            }
        }
Exemple #34
0
 void ProcessLoadPacket(LoadPacket pkt)
 {
     Console.WriteLine("Client load packet");
     character = db0.LoadCharacter(account, pkt.CharacterId);
     if (character != null)
     {
         if (character.Dead)
             SendPacket(new svrPackets.FailurePacket()
             {
                 Message = "Character is dead."
             });
         else
         {
             SendPacket(new CreateResultPacket()
             {
                 CharacterID = character.CharacterId,
                 ObjectID = RealmManager.Worlds[targetWorld].EnterWorld(entity = new Player(this))
             });
             stage = ProtocalStage.Ready;
         }
     }
     else
         SendPacket(new svrPackets.FailurePacket()
         {
             Message = "Failed to Load character."
         });
 }
        void ProcessHelloPacket(HelloPacket pkt)
        {
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                account = Database.Register(pkt.GUID, pkt.Password, true);
                if (account == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });
                    return;
                }
            }
            if (!RealmManager.TryConnect(this))
            {
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
            }
            else
            {
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                }
                else
                {
                    if (world.Id == -6) //Test World
                        (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                    else if (world.IsLimbo)
                        world = world.GetInstance(this);

                    var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                    Random = new wRandom(seed);
                    targetWorld = world.Id;
                    SendPacket(new MapInfoPacket()
                    {
                        Width = world.Map.Width,
                        Height = world.Map.Height,
                        Name = world.Name,
                        Seed = seed,
                        Background = world.Background,
                        AllowTeleport = world.AllowTeleport,
                        ShowDisplays = world.ShowDisplays,
                        ClientXML = world.ClientXML,
                        ExtraXML = world.ExtraXML
                    });
                    stage = ProtocalStage.Handshaked;
                }
            }
        }