示例#1
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");
                }
            }
        }
示例#2
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;
            }
        }
示例#3
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;
                }
            }
        }
        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;
            }
        }