Esempio n. 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");
                }
            }
        }
Esempio n. 2
0
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db1 = new Database())
            {

                chrs = new Chars()
                {
                    Characters = new List<Char>() { },
                    NextCharId = 2,
                    MaxNumChars = 1,
                    Account = db1.Verify(query["guid"], query["password"]),
                    Servers = new List<ServerItem>() //leave this list empty for the Oryx Sleeping message
                    {
                        new ServerItem()
                        {
                            Name = "Local",
                            Lat = 22.28,
                            Long = 114.16,
                            DNS = "127.0.0.1",//db.confreader.getservers(false).ToString(), //127.0.0.1, CHANGE THIS TO LET YOUR FRIENDS CONNECT
                            Usage = 0.2,
                            AdminOnly = false
                        }
                        //new ServerItem()
                        //{
                        //    Name = "Admin Realm",
                        //    Lat = 22.28,
                        //    Long = 114.16,
                        //    DNS = "127.0.0.1",
                        //    Usage = 0.2,
                        //    AdminOnly = true
                        //}
                    }
                };
                Account dvh = null;
                if (chrs.Account != null)
                {
                    db1.GetCharData(chrs.Account, chrs);
                    db1.LoadCharacters(chrs.Account, chrs);
                    chrs.News = db1.GetNews(chrs.Account);
                    dvh = chrs.Account;
                    if (db1.getRole(chrs.Account) >= (int)Database.Roles.Moderator)
                    {
                        chrs.Account.Admin = true;
                    }
                }
                else
                {
                    chrs.Account = Database.CreateGuestAccount(query["guid"]);
                    chrs.News = db1.GetNews(null);
                }
                if (dvh != null && db1.isWhitelisted(dvh) == false)
                {
                    chrs = Whitelist.whitelisted;
                }
                if (dvh != null && db1.isBanned(dvh) == true)
                {
                    chrs = new Chars();
                }
                MemoryStream ms = new MemoryStream();
                XmlSerializer serializer = new XmlSerializer(chrs.GetType(), new XmlRootAttribute(chrs.GetType().Name) { Namespace = "" });

                XmlWriterSettings xws = new XmlWriterSettings();
                xws.OmitXmlDeclaration = true;
                xws.Encoding = Encoding.UTF8;
                XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
                serializer.Serialize(xtw, chrs, chrs.Namespaces);
            }
        }