Exemple #1
0
        public static User getAddUser(CommandReader cr, User user)
        {
            User res = new User();

            res.id              = cr.getInt();
            res.shipName        = cr.getStr();
            res.x               = cr.getInt();
            res.y               = cr.getInt();
            res.domain          = cr.getInt();
            res.userShip.energy = cr.getDbl();
            double angle = cr.getDbl();

            res.equips = getEquips(cr, user);
            res.updateUserShip();
            return(res);
        }
Exemple #2
0
        public static void getLocations(CommandReader cr, User user)
        {
            int locationCount = cr.getInt();

            for (int i = 0; i < locationCount; i++)
            {
                Location loc = new Location();
                loc.id       = cr.getInt();
                loc.starName = cr.getStr();
                loc.starType = cr.getInt();
                loc.x        = cr.getInt();
                loc.y        = cr.getInt();
                loc.radius   = cr.getInt();
                loc.domain   = cr.getInt();
                user.locations.Add(loc.id, loc);
            }
        }
Exemple #3
0
        public static Dictionary <int, Nebula> getNebulas(CommandReader cr)
        {
            Dictionary <int, Nebula> res = new Dictionary <int, Nebula>();
            int nebulasCount             = cr.getInt();

            for (int i = 0; i < nebulasCount; i++)
            {
                Nebula neb = new Nebula();
                neb.id    = cr.getInt();
                neb.type  = cr.getInt();
                neb.x     = cr.getInt();
                neb.y     = cr.getInt();
                neb.scale = cr.getInt();
                neb.angle = cr.getInt();
                res.Add(neb.id, neb);
            }
            return(res);
        }
Exemple #4
0
        public static Dictionary <int, Domain> getDomains(CommandReader cr)
        {
            Dictionary <int, Domain> res = new Dictionary <int, Domain>();
            int domainCount = cr.getInt();

            for (int i = 0; i < domainCount; i++)
            {
                Domain dom = new Domain();
                dom.id          = cr.getInt();
                dom.color       = cr.getInt();
                dom.description = cr.getStr();
                dom.x           = cr.getInt();
                dom.y           = cr.getInt();
                int enemyCount = cr.getInt();
                for (int j = 0; j < enemyCount; j++)
                {
                    dom.enemy.Add(cr.getInt());
                }
                res.Add(dom.id, dom);
            }
            return(res);
        }
Exemple #5
0
        public static void getPlanets(CommandReader cr, User user)
        {
            Location parentLocation = user.locations[cr.getInt()];

            parentLocation.planets      = new Dictionary <int, Planet>();
            parentLocation.isLoadPlanet = true;
            int planetsCount = cr.getInt();

            for (int i = 0; i < planetsCount; i++)
            {
                Planet pln = new Planet();
                pln.parent            = parentLocation;
                pln.id                = cr.getInt();
                pln.planetName        = cr.getStr();
                pln.planetType        = cr.getInt();
                pln.r_speed           = cr.getInt();
                pln.orbit             = cr.getInt();
                pln.radius            = cr.getInt();
                pln.color             = cr.getInt();
                pln.atmosphere        = cr.getInt();
                pln.domain            = cr.getInt();
                pln.atmosphere_speedX = cr.getInt();
                pln.atmosphere_speedY = cr.getInt();
                pln.price_coef        = cr.getInt();
                int srvsCount = cr.getInt();
                for (int j = 0; j < srvsCount; j++)
                {
                    pln.services.Add(cr.getInt());
                }
                if (!parentLocation.planets.ContainsKey(pln.id))
                {
                    parentLocation.planets.Add(pln.id, pln);
                }
                if (!user.planets.ContainsKey(pln.id))
                {
                    user.planets.Add(pln.id, pln);
                }
            }
        }
Exemple #6
0
        public static User getUserData(CommandReader cr, User user)
        {
            User res = user;

            res.id     = cr.getInt();
            res.x      = cr.getInt();
            res.y      = cr.getInt();
            res.domain = cr.getInt();
            int inPlanet = cr.getInt();

            if (inPlanet == 0)
            {
                res.inPlanet = null;
            }
            else
            {
                res.inPlanet = user.planets[inPlanet];
            }
            res.pilotName       = cr.getStr();
            res.shipName        = cr.getStr();
            res.userShip.energy = cr.getDbl();
            res.equips          = getEquips(cr, user);
            return(res);
        }
Exemple #7
0
        public void doWork(object param)
        {
            if (param is ReceiverParams)
            {
                ReceiverParams p = (ReceiverParams)param;
                user = p.user;
            }
            if (user != null)
            {
                while (isWork)
                {
                    Command       command   = user.client.waitCommand(user.handler);
                    CommandReader cmdReader = new CommandReader(command);
                    switch (command.idCommand)
                    {
                    case Command.CList.LoginUser:
                    {
                        user.serverTime = cmdReader.getInt();
                        if (!MainData.isLoaded && !MainData.isDomains && !MainData.loadingDomains)
                        {
                            MainData.loadingDomains = true;
                            user.client.sendCommand(new Command(Command.CList.getDomains), user.handler);
                        }
                        break;
                    }

                    case Command.CList.FailLogin:
                    {
                        user.error = User.ErrorList.Password;
                        isWork     = false;
                        break;
                    }

                    case Command.CList.FailVersion:
                    {
                        user.error = User.ErrorList.Protocol;
                        isWork     = false;
                        break;
                    }

                    case Command.CList.getDomains:
                    {
                        MainData.domains        = Loader.getDomains(cmdReader);
                        MainData.isDomains      = true;
                        MainData.loadingDomains = false;
                        break;
                    }

                    case Command.CList.getNebulas:
                    {
                        MainData.nebulas        = Loader.getNebulas(cmdReader);
                        MainData.isNebulas      = true;
                        MainData.loadingNebulas = false;
                        break;
                    }

                    case Command.CList.getLocations:
                    {
                        Loader.getLocations(cmdReader, user);
                        for (int i = 0; i < user.locations.Count; i++)
                        {
                            user.log += "LoadLocation: " + user.locations.ElementAt(i).Value.starName + "\r\n";
                            if (!user.locations.ElementAt(i).Value.isLoadPlanet)
                            {
                                List <byte> rawData = new List <byte>();
                                rawData.AddRange(user.client.intToByteArray(user.locations.ElementAt(i).Value.id));
                                user.client.sendCommand(new Command(Command.CList.getPlanets, rawData.ToArray()), user.handler);
                            }
                        }
                        break;
                    }

                    case Command.CList.getPlanets:
                    {
                        Loader.getPlanets(cmdReader, user);
                        break;
                    }

                    case Command.CList.touchUser:
                    {
                        MoveUser moveUser = Loader.getTouchUser(cmdReader, user);
                        if (moveUser.userId == user.id)
                        {
                            user.moveUser         = moveUser;
                            user.moveUser.mStatus = MoveUser.MoveStatus.move;
                        }
                        break;
                    }

                    case Command.CList.getItems:
                    {
                        MainData.itemCollect  = Loader.getItems(cmdReader, user);
                        MainData.isItems      = true;
                        MainData.loadingItems = false;
                        break;
                    }

                    case Command.CList.getPlayerData:
                    {
                        user = Loader.getUserData(cmdReader, user);
                        user.isLoadComplite = true;
                        Action action = user.ai.start;
                        action.BeginInvoke(null, null);
                        break;
                    }

                    case Command.CList.addUser:
                    {
                        User userAdd = Loader.getAddUser(cmdReader, user);
                        if (!MainData.users.ContainsKey(userAdd.id))
                        {
                            lock (MainData.users)
                            {
                                MainData.users.Add(userAdd.id, userAdd);
                            }
                        }
                        //user.usersClose.Add(userAdd.id, userAdd);
                        Action action = user.ai.newObject;
                        action.BeginInvoke(null, null);
                        break;
                    }

                    case Command.CList.removeUser:
                    {
                        user.usersClose.Remove(Loader.getRemoveUser(cmdReader));
                        Action action = user.ai.removeObject;
                        action.BeginInvoke(null, null);
                        break;
                    }

                    case Command.CList.Disconnect:
                    {
                        isWork = false;
                        break;
                    }

                    case Command.CList.useEquips:
                    {
                        Loader.getUseEquip(cmdReader, user);
                        Action action = user.ai.newAction;
                        action.BeginInvoke(null, null);
                        break;
                    }
                    }
                }
            }
        }
Exemple #8
0
        public static int getRemoveUser(CommandReader cr)
        {
            int res = cr.getInt();

            return(res);
        }
Exemple #9
0
        public static Dictionary <int, Equip> getEquips(CommandReader cr, User user)
        {
            Dictionary <int, Equip> res = new Dictionary <int, Equip>();
            int equipCount = cr.getInt();

            for (int i = 0; i < equipCount; i++)
            {
                Equip eq = new Equip();
                eq.id = cr.getInt();
                int           item_id = cr.getInt();
                Item.ItemType iType   = (Item.ItemType)cr.getInt();
                int           dType   = cr.getInt();
                eq.in_use = cr.getInt() == 0 ? false: true;
                eq.wear   = cr.getInt();
                int location = cr.getInt();
                eq.location = location == 0 ? null : user.planets[location];
                eq.num      = cr.getInt();
                eq.last_use = cr.getDbl();
                switch (iType)
                {
                case Item.ItemType.consumable:
                {
                    Consumable item = MainData.itemCollect.get <Consumable>(item_id);
                    eq.item = item;
                    break;
                }

                case Item.ItemType.device:
                {
                    Device.DeviceType devT = (Device.DeviceType)dType;
                    switch (devT)
                    {
                    case Device.DeviceType.Body:
                    {
                        Body item = MainData.itemCollect.get <Body>(item_id);
                        eq.item = item;
                        break;
                    }

                    case Device.DeviceType.Droid:
                    {
                        Droid item = MainData.itemCollect.get <Droid>(item_id);
                        eq.item = item;
                        break;
                    }

                    case Device.DeviceType.Engine:
                    {
                        Engine item = MainData.itemCollect.get <Engine>(item_id);
                        eq.item = item;
                        break;
                    }

                    case Device.DeviceType.Fuelbag:
                    {
                        Fuelbag item = MainData.itemCollect.get <Fuelbag>(item_id);
                        eq.item = item;
                        break;
                    }

                    case Device.DeviceType.Hyper:
                    {
                        Hyper item = MainData.itemCollect.get <Hyper>(item_id);
                        eq.item = item;
                        break;
                    }

                    case Device.DeviceType.Radar:
                    {
                        Radar item = MainData.itemCollect.get <Radar>(item_id);
                        eq.item = item;
                        break;
                    }

                    case Device.DeviceType.Shield:
                    {
                        Shield item = MainData.itemCollect.get <Shield>(item_id);
                        eq.item = item;
                        break;
                    }

                    case Device.DeviceType.Weapon:
                    {
                        Weapon item = MainData.itemCollect.get <Weapon>(item_id);
                        eq.item = item;
                        break;
                    }
                    }
                    break;
                }
                }
                res.Add(eq.id, eq);
            }
            return(res);
        }
Exemple #10
0
        public static ItemCollection getItems(CommandReader cr, User user)
        {
            ItemCollection res           = new ItemCollection();
            int            itemTypeCount = cr.getInt();

            for (int i = 0; i < itemTypeCount; i++)
            {
                int itemCount = cr.getInt();
                for (int j = 0; j < itemCount; j++)
                {
                    int           item_id          = cr.getInt();
                    Item.ItemType item_itemType    = (Item.ItemType)cr.getInt();
                    String        item_description = cr.getStr();
                    int           item_volume      = cr.getInt();
                    int           item_region_id   = cr.getInt();
                    int           item_use_only    = cr.getInt();
                    int           item_price       = cr.getInt();
                    switch (item_itemType)
                    {
                    case Item.ItemType.consumable:
                    {
                        Consumable item = new Consumable();
                        item.id          = item_id;
                        item.itemType    = item_itemType;
                        item.description = item_description;
                        item.volume      = item_volume;
                        item.region      = item_region_id;
                        res.consumables.Add(item.id, item);
                        break;
                    }

                    case Item.ItemType.device:
                    {
                        String            device_vendorStr  = cr.getStr();
                        Device.DeviceType device_deviceType = (Device.DeviceType)cr.getInt();
                        int device_durability = cr.getInt();
                        switch (device_deviceType)
                        {
                        case Device.DeviceType.Body:
                        {
                            Body dev = new Body();
                            int  body_slot_weapons = cr.getInt();
                            int  body_slot_droids  = cr.getInt();
                            int  body_slot_shield  = cr.getInt();
                            int  body_slot_hyper   = cr.getInt();
                            dev.id           = item_id;
                            dev.itemType     = item_itemType;
                            dev.description  = item_description;
                            dev.volume       = item_volume;
                            dev.region       = item_region_id;
                            dev.vendorStr    = device_vendorStr;
                            dev.deviceType   = device_deviceType;
                            dev.durability   = device_durability;
                            dev.use_only     = item_use_only;
                            dev.price        = item_price;
                            dev.slot_weapons = body_slot_weapons;
                            dev.slot_droids  = body_slot_droids;
                            dev.slot_shield  = body_slot_shield;
                            dev.slot_hyper   = body_slot_hyper;
                            res.bodyes.Add(dev.id, dev);
                            break;
                        }

                        case Device.DeviceType.Droid:
                        {
                            Droid dev               = new Droid();
                            int   droid_power       = cr.getInt();
                            int   droid_time_reload = cr.getInt();
                            int   radius            = cr.getInt();
                            dev.id          = item_id;
                            dev.itemType    = item_itemType;
                            dev.description = item_description;
                            dev.volume      = item_volume;
                            dev.region      = item_region_id;
                            dev.vendorStr   = device_vendorStr;
                            dev.deviceType  = device_deviceType;
                            dev.durability  = device_durability;
                            dev.use_only    = item_use_only;
                            dev.price       = item_price;
                            dev.power       = droid_power;
                            dev.time_reload = droid_time_reload;
                            res.droids.Add(dev.id, dev);
                            break;
                        }

                        case Device.DeviceType.Engine:
                        {
                            Engine dev             = new Engine();
                            int    engine_power    = cr.getInt();
                            int    engine_economic = cr.getInt();
                            dev.id          = item_id;
                            dev.itemType    = item_itemType;
                            dev.description = item_description;
                            dev.volume      = item_volume;
                            dev.region      = item_region_id;
                            dev.vendorStr   = device_vendorStr;
                            dev.deviceType  = device_deviceType;
                            dev.durability  = device_durability;
                            dev.use_only    = item_use_only;
                            dev.price       = item_price;
                            dev.power       = engine_power;
                            dev.economic    = engine_economic;
                            res.engines.Add(dev.id, dev);
                            break;
                        }

                        case Device.DeviceType.Fuelbag:
                        {
                            Fuelbag dev = new Fuelbag();
                            int     fuelbag_compress = cr.getInt();
                            dev.id          = item_id;
                            dev.itemType    = item_itemType;
                            dev.description = item_description;
                            dev.volume      = item_volume;
                            dev.region      = item_region_id;
                            dev.vendorStr   = device_vendorStr;
                            dev.deviceType  = device_deviceType;
                            dev.durability  = device_durability;
                            dev.use_only    = item_use_only;
                            dev.price       = item_price;
                            dev.compress    = fuelbag_compress;
                            res.fuelbags.Add(dev.id, dev);
                            break;
                        }

                        case Device.DeviceType.Hyper:
                        {
                            Hyper dev               = new Hyper();
                            int   hyper_radius      = cr.getInt();
                            int   hyper_time_start  = cr.getInt();
                            int   hyper_time_reload = cr.getInt();
                            dev.id          = item_id;
                            dev.itemType    = item_itemType;
                            dev.description = item_description;
                            dev.volume      = item_volume;
                            dev.region      = item_region_id;
                            dev.vendorStr   = device_vendorStr;
                            dev.deviceType  = device_deviceType;
                            dev.durability  = device_durability;
                            dev.use_only    = item_use_only;
                            dev.price       = item_price;
                            dev.radius      = hyper_radius;
                            dev.time_start  = hyper_time_start;
                            dev.time_reload = hyper_time_reload;
                            res.hypers.Add(dev.id, dev);
                            break;
                        }

                        case Device.DeviceType.Radar:
                        {
                            Radar dev           = new Radar();
                            int   radar_radius  = cr.getInt();
                            int   radar_defense = cr.getInt();
                            int   big_radius    = cr.getInt();
                            dev.id          = item_id;
                            dev.itemType    = item_itemType;
                            dev.description = item_description;
                            dev.volume      = item_volume;
                            dev.region      = item_region_id;
                            dev.vendorStr   = device_vendorStr;
                            dev.deviceType  = device_deviceType;
                            dev.durability  = device_durability;
                            dev.use_only    = item_use_only;
                            dev.price       = item_price;
                            dev.radius      = radar_radius;
                            dev.defense     = radar_defense;
                            dev.hyper       = big_radius;
                            res.radars.Add(dev.id, dev);
                            break;
                        }

                        case Device.DeviceType.Shield:
                        {
                            Shield dev          = new Shield();
                            int    shield_power = cr.getInt();
                            dev.id          = item_id;
                            dev.itemType    = item_itemType;
                            dev.description = item_description;
                            dev.volume      = item_volume;
                            dev.region      = item_region_id;
                            dev.vendorStr   = device_vendorStr;
                            dev.deviceType  = device_deviceType;
                            dev.durability  = device_durability;
                            dev.use_only    = item_use_only;
                            dev.price       = item_price;
                            dev.power       = shield_power;
                            res.shields.Add(dev.id, dev);
                            break;
                        }

                        case Device.DeviceType.Weapon:
                        {
                            Weapon dev = new Weapon();
                            int    weapon_weaponType  = cr.getInt();
                            int    weapon_radius      = cr.getInt();
                            int    weapon_power       = cr.getInt();
                            int    weapon_time_start  = cr.getInt();
                            int    weapon_time_reload = cr.getInt();
                            dev.id          = item_id;
                            dev.itemType    = item_itemType;
                            dev.description = item_description;
                            dev.volume      = item_volume;
                            dev.region      = item_region_id;
                            dev.vendorStr   = device_vendorStr;
                            dev.deviceType  = device_deviceType;
                            dev.durability  = device_durability;
                            dev.use_only    = item_use_only;
                            dev.price       = item_price;
                            dev.weaponType  = (Weapon.WeaponType)weapon_weaponType;
                            dev.radius      = weapon_radius;
                            dev.power       = weapon_power;
                            dev.time_start  = weapon_time_start;
                            dev.time_reload = weapon_time_reload;
                            res.weapons.Add(dev.id, dev);
                            break;
                        }
                        }
                        break;
                    }
                    }
                }
            }
            return(res);
        }