private void doWeather(ConnectedPlayer client, string weatherID, string value)
        {
            ushort weather = Convert.ToUInt16(weatherID);

            if (client != null)
            {
                client.queuePacket(BasePacket.createPacket(SetWeatherPacket.buildPacket(client.actorID, weather, Convert.ToUInt16(value)), true, false));
            }

            /*
             * WIP: Change weather serverside, currently only clientside
             *
             * uint currentZoneID;
             * if (client != null)
             * {
             *  currentZoneID = client.getActor().zoneId;
             *
             *  foreach (KeyValuePair<uint, ConnectedPlayer> entry in mConnectedPlayerList)
             *  {
             *      // Change the weather for everyone in the same zone
             *      if (currentZoneID == entry.Value.getActor().zoneId)
             *      {
             *          BasePacket weatherPacket = BasePacket.createPacket(SetWeatherPacket.buildPacket(entry.Value.actorID, weather), true, false);
             *          entry.Value.queuePacket(weatherPacket);
             *      }
             *  }
             * }
             */
        }
        public void doMusic(ConnectedPlayer client, string music)
        {
            ushort musicId;

            if (music.ToLower().StartsWith("0x"))
            {
                musicId = Convert.ToUInt16(music, 16);
            }
            else
            {
                musicId = Convert.ToUInt16(music);
            }

            if (client != null)
            {
                client.queuePacket(BasePacket.createPacket(SetMusicPacket.buildPacket(client.actorID, musicId, 1), true, false));
            }
            else
            {
                foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
                {
                    BasePacket musicPacket = BasePacket.createPacket(SetMusicPacket.buildPacket(entry.Value.actorID, musicId, 1), true, false);
                    entry.Value.queuePacket(musicPacket);
                }
            }
        }
        public void doWarp(ConnectedPlayer client, uint zoneId, string privateArea, byte spawnType, float x, float y, float z, float r)
        {
            WorldManager worldManager = Server.GetWorldManager();

            if (worldManager.GetZone(zoneId) == null)
            {
                if (client != null)
                {
                    client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "Zone does not exist or setting isn't valid."), true, false));
                }
                Log.error("Zone does not exist or setting isn't valid.");
            }

            if (client != null)
            {
                worldManager.DoZoneChange(client.getActor(), zoneId, privateArea, spawnType, x, y, z, r);
            }
            else
            {
                foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
                {
                    worldManager.DoZoneChange(entry.Value.getActor(), zoneId, privateArea, spawnType, x, y, z, r);
                }
            }
        }
 public void printPos(ConnectedPlayer client)
 {
     if (client != null)
     {
         Player p = client.getActor();
         client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", String.Format("{0}\'s position: ZoneID: {1}, X: {2}, Y: {3}, Z: {4}, Rotation: {5}", p.customDisplayName, p.zoneId, p.positionX, p.positionY, p.positionZ, p.rotation)), true, false));
     }
     else
     {
         foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
         {
             Player p = entry.Value.getActor();
             Log.info(String.Format("{0}\'s position: ZoneID: {1}, X: {2}, Y: {3}, Z: {4}, Rotation: {5}", p.customDisplayName, p.zoneId, p.positionX, p.positionY, p.positionZ, p.rotation));
         }
     }
 }
        public void sendPacket(ConnectedPlayer client, string path)
        {
            BasePacket packet = new BasePacket(path);

            if (client != null)
            {
                packet.replaceActorID(client.actorID);
                client.queuePacket(packet);
            }
            else
            {
                foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
                {
                    packet.replaceActorID(entry.Value.actorID);
                    entry.Value.queuePacket(packet);
                }
            }
        }
示例#6
0
        public void sendZoneInPackets(WorldManager world, ushort spawnType)
        {
            queuePacket(SetActorIsZoningPacket.buildPacket(actorId, actorId, false));
            queuePacket(_0x10Packet.buildPacket(actorId, 0xFF));
            queuePacket(SetMusicPacket.buildPacket(actorId, zone.bgmDay, 0x01));
            queuePacket(SetWeatherPacket.buildPacket(actorId, SetWeatherPacket.WEATHER_CLEAR, 1));

            queuePacket(SetMapPacket.buildPacket(actorId, zone.regionId, zone.actorId));

            queuePacket(getSpawnPackets(actorId, spawnType));
            getSpawnPackets(actorId, spawnType).debugPrintPacket();

            #region grouptest
            //Retainers
            List <ListEntry> retainerListEntries = new List <ListEntry>();
            retainerListEntries.Add(new ListEntry(actorId, 0xFFFFFFFF, 0x139E, false, true, customDisplayName));
            retainerListEntries.Add(new ListEntry(0x23, 0x0, 0xFFFFFFFF, false, false, "TEST1"));
            retainerListEntries.Add(new ListEntry(0x24, 0x0, 0xFFFFFFFF, false, false, "TEST2"));
            retainerListEntries.Add(new ListEntry(0x25, 0x0, 0xFFFFFFFF, false, false, "TEST3"));
            BasePacket retainerListPacket = BasePacket.createPacket(ListUtils.createRetainerList(actorId, 0xF4, 1, 0x800000000004e639, retainerListEntries), true, false);
            playerSession.queuePacket(retainerListPacket);

            //Party
            List <ListEntry> partyListEntries = new List <ListEntry>();
            partyListEntries.Add(new ListEntry(actorId, 0xFFFFFFFF, 0xFFFFFFFF, false, true, customDisplayName));
            partyListEntries.Add(new ListEntry(0x029B27D3, 0xFFFFFFFF, 0x195, false, true, "Valentine Bluefeather"));
            BasePacket partyListPacket = BasePacket.createPacket(ListUtils.createPartyList(actorId, 0xF4, 1, 0x8000000000696df2, partyListEntries), true, false);
            playerSession.queuePacket(partyListPacket);
            #endregion

            #region Inventory & Equipment
            queuePacket(InventoryBeginChangePacket.buildPacket(actorId));
            inventories[Inventory.NORMAL].sendFullInventory();
            inventories[Inventory.CURRENCY].sendFullInventory();
            inventories[Inventory.KEYITEMS].sendFullInventory();
            inventories[Inventory.BAZAAR].sendFullInventory();
            inventories[Inventory.MELDREQUEST].sendFullInventory();
            inventories[Inventory.LOOT].sendFullInventory();
            equipment.SendFullEquipment(false);
            playerSession.queuePacket(InventoryEndChangePacket.buildPacket(actorId), true, false);
            #endregion

            playerSession.queuePacket(getInitPackets(actorId));


            BasePacket areaMasterSpawn      = zone.getSpawnPackets(actorId);
            BasePacket debugSpawn           = world.GetDebugActor().getSpawnPackets(actorId);
            BasePacket worldMasterSpawn     = world.GetActor().getSpawnPackets(actorId);
            BasePacket weatherDirectorSpawn = new WeatherDirector(this, 8003).getSpawnPackets(actorId);
            BasePacket directorSpawn        = null;

            if (currentDirector != null)
            {
                directorSpawn = currentDirector.getSpawnPackets(actorId);
            }

            playerSession.queuePacket(areaMasterSpawn);
            playerSession.queuePacket(debugSpawn);
            if (directorSpawn != null)
            {
                //directorSpawn.debugPrintPacket();
                // currentDirector.getInitPackets(actorId).debugPrintPacket();
                queuePacket(directorSpawn);
                queuePacket(currentDirector.getInitPackets(actorId));
                //queuePacket(currentDirector.getSetEventStatusPackets(actorId));
            }
            playerSession.queuePacket(worldMasterSpawn);

            if (zone.isInn)
            {
                SetCutsceneBookPacket cutsceneBookPacket = new SetCutsceneBookPacket();
                for (int i = 0; i < 2048; i++)
                {
                    cutsceneBookPacket.cutsceneFlags[i] = true;
                }

                SubPacket packet = cutsceneBookPacket.buildPacket(actorId, "<Path Companion>", 11, 1, 1);

                packet.debugPrintSubPacket();
                queuePacket(packet);
            }

            playerSession.queuePacket(weatherDirectorSpawn);

/*
 #region hardcode
 *          BasePacket reply10 = new BasePacket("./packets/login/login10.bin"); //Item Storage, Inn Door created
 *          BasePacket reply11 = new BasePacket("./packets/login/login11.bin"); //NPC Create ??? Final init
 *          reply10.replaceActorID(actorId);
 *          reply11.replaceActorID(actorId);
 *          //playerSession.queuePacket(reply10);
 *         // playerSession.queuePacket(reply11);
 #endregion
 */
        }
        internal bool doCommand(string input, ConnectedPlayer client)
        {
            input.Trim();
            if (input.StartsWith("!"))
            {
                input = input.Substring(1);
            }

            String[] split = input.Split(' ');
            split = split.Select(temp => temp.ToLower()).ToArray(); // Ignore case on commands
            split = split.Where(temp => temp != "").ToArray();      // strips extra whitespace from commands

            // Debug
            //sendMessage(client, string.Join(",", split));

            if (split.Length >= 1)
            {
                #region !help
                if (split[0].Equals("help"))
                {
                    if (split.Length == 1)
                    {
                        sendMessage(client, Resources.CPhelp);
                    }
                    if (split.Length == 2)
                    {
                        if (split[1].Equals("mypos"))
                        {
                            sendMessage(client, Resources.CPmypos);
                        }
                        else if (split[1].Equals("music"))
                        {
                            sendMessage(client, Resources.CPmusic);
                        }
                        else if (split[1].Equals("warp"))
                        {
                            sendMessage(client, Resources.CPwarp);
                        }
                        else if (split[1].Equals("givecurrency"))
                        {
                            sendMessage(client, Resources.CPgivecurrency);
                        }
                        else if (split[1].Equals("giveitem"))
                        {
                            sendMessage(client, Resources.CPgiveitem);
                        }
                        else if (split[1].Equals("givekeyitem"))
                        {
                            sendMessage(client, Resources.CPgivekeyitem);
                        }
                        else if (split[1].Equals("removecurrency"))
                        {
                            sendMessage(client, Resources.CPremovecurrency);
                        }
                        else if (split[1].Equals("removeitem"))
                        {
                            sendMessage(client, Resources.CPremoveitem);
                        }
                        else if (split[1].Equals("removekeyitem"))
                        {
                            sendMessage(client, Resources.CPremovekeyitem);
                        }
                        else if (split[1].Equals("reloaditems"))
                        {
                            sendMessage(client, Resources.CPreloaditems);
                        }
                        else if (split[1].Equals("reloadzones"))
                        {
                            sendMessage(client, Resources.CPreloadzones);
                        }

                        /*
                         * else if (split[1].Equals("property"))
                         *  sendMessage(client, Resources.CPproperty);
                         * else if (split[1].Equals("property2"))
                         *  sendMessage(client, Resources.CPproperty2);
                         * else if (split[1].Equals("sendpacket"))
                         *   sendMessage(client, Resources.CPsendpacket);
                         * else if (split[1].Equals("setgraphic"))
                         *     sendMessage(client, Resources.CPsetgraphic);
                         */
                    }
                    if (split.Length == 3)
                    {
                        if (split[1].Equals("test"))
                        {
                            if (split[2].Equals("weather"))
                            {
                                sendMessage(client, Resources.CPtestweather);
                            }
                        }
                    }

                    return(true);
                }
                #endregion

                #region !test
                else if (split[0].Equals("test"))
                {
                    if (split.Length == 1)
                    {
                        // catch invalid commands
                        sendMessage(client, Resources.CPhelp);
                    }
                    else if (split.Length >= 2)
                    {
                        #region !test weather
                        if (split[1].Equals("weather"))
                        {
                            try
                            {
                                doWeather(client, split[2], split[3]);
                                return(true);
                            }
                            catch (Exception e)
                            {
                                Log.error("Could not change weather: " + e);
                            }
                        }
                        #endregion
                    }
                }
                #endregion

                #region !mypos
                else if (split[0].Equals("mypos"))
                {
                    try
                    {
                        printPos(client);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not load packet: " + e);
                    }
                }
                #endregion

                #region !reloadzones
                else if (split[0].Equals("reloadzones"))
                {
                    if (client != null)
                    {
                        Log.info(String.Format("Got request to reset zone: {0}", client.getActor().zoneId));
                        client.getActor().zone.clear();
                        client.getActor().zone.addActorToZone(client.getActor());
                        client.getActor().sendInstanceUpdate();
                        client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", String.Format("Reseting zone {0}...", client.getActor().zoneId)), true, false));
                    }
                    Server.GetWorldManager().reloadZone(client.getActor().zoneId);
                    return(true);
                }
                #endregion

                #region !reloaditems
                else if (split[0].Equals("reloaditems"))
                {
                    Log.info(String.Format("Got request to reload item gamedata"));
                    sendMessage(client, "Reloading Item Gamedata...");
                    gamedataItems.Clear();
                    gamedataItems = Database.getItemGamedata();
                    Log.info(String.Format("Loaded {0} items.", gamedataItems.Count));
                    sendMessage(client, String.Format("Loaded {0} items.", gamedataItems.Count));
                    return(true);
                }
                #endregion

                #region !sendpacket
                else if (split[0].Equals("sendpacket"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        sendPacket(client, "./packets/" + split[1]);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not load packet: " + e);
                    }
                }
                #endregion

                #region !graphic
                else if (split[0].Equals("graphic"))
                {
                    try
                    {
                        if (split.Length == 6)
                        {
                            setGraphic(client, UInt32.Parse(split[1]), UInt32.Parse(split[2]), UInt32.Parse(split[3]), UInt32.Parse(split[4]), UInt32.Parse(split[5]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give item.");
                    }
                }
                #endregion

                #region !giveitem
                else if (split[0].Equals("giveitem"))
                {
                    try
                    {
                        if (split.Length == 2)
                        {
                            giveItem(client, UInt32.Parse(split[1]), 1);
                        }
                        else if (split.Length == 3)
                        {
                            giveItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                        else if (split.Length == 4)
                        {
                            giveItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]), UInt16.Parse(split[3]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give item.");
                    }
                }
                #endregion

                #region !removeitem
                else if (split[0].Equals("removeitem"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        if (split.Length == 2)
                        {
                            removeItem(client, UInt32.Parse(split[1]), 1);
                        }
                        else if (split.Length == 3)
                        {
                            removeItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                        else if (split.Length == 4)
                        {
                            removeItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]), UInt16.Parse(split[3]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not remove item.");
                    }
                }
                #endregion

                #region !givekeyitem
                else if (split[0].Equals("givekeyitem"))
                {
                    try
                    {
                        if (split.Length == 2)
                        {
                            giveKeyItem(client, UInt32.Parse(split[1]));
                        }
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give keyitem.");
                    }
                }
                #endregion

                #region !removekeyitem
                else if (split[0].Equals("removekeyitem"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        if (split.Length == 2)
                        {
                            removeKeyItem(client, UInt32.Parse(split[1]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not remove keyitem.");
                    }
                }
                #endregion

                #region !givecurrency
                else if (split[0].Equals("givecurrency"))
                {
                    try
                    {
                        if (split.Length == 2)
                        {
                            giveCurrency(client, ITEM_GIL, Int32.Parse(split[1]));
                        }
                        else if (split.Length == 3)
                        {
                            giveCurrency(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give currency.");
                    }
                }
                #endregion

                #region !removecurrency
                else if (split[0].Equals("removecurrency"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        if (split.Length == 2)
                        {
                            removeCurrency(client, ITEM_GIL, Int32.Parse(split[1]));
                        }
                        else if (split.Length == 3)
                        {
                            removeCurrency(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not remove currency.");
                    }
                }
                #endregion

                #region !music
                else if (split[0].Equals("music"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        doMusic(client, split[1]);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not change music: " + e);
                    }
                }
                #endregion

                #region !warp
                else if (split[0].Equals("warp"))
                {
                    parseWarp(client, split);
                    return(true);
                }
                #endregion

                #region !property
                else if (split[0].Equals("property"))
                {
                    if (split.Length == 4)
                    {
                        changeProperty(Utils.MurmurHash2(split[1], 0), Convert.ToUInt32(split[2], 16), split[3]);
                    }
                    return(true);
                }
                #endregion

                #region !property2
                else if (split[0].Equals("property2"))
                {
                    if (split.Length == 4)
                    {
                        changeProperty(Convert.ToUInt32(split[1], 16), Convert.ToUInt32(split[2], 16), split[3]);
                    }
                    return(true);
                }
                #endregion
            }
            return(false);
        }
示例#8
0
        public void tick()
        {
            if (gameState == GameState.INGAME && players.Count == 0)
            {
                Close();
            }

            foreach (var pp in this.potentialPlayers)
            {
                if (pp.shouldDelete || pp.hasError || !pp.socket.Connected)
                {
                    continue;
                }
                if (!pp.isConnected) //new player, handle them.
                {
                    if (gameState != GameState.LOBBY)
                    {
                        pp.rejectJoin((int)REJECTJOIN.STARTED);
                        pp.shouldDelete = true;
                    }
                    pp.isConnected = true;

                    if (players.Count + 1 >= gameMap.MapNumPlayers)
                    {
                        RemoveFakeHost();
                    }

                    byte pid = GetNextPID();
                    byte sid = GetOpenSlotID();


                    if (sid == 0xff || pid == 0xff) //open slot not found, open pid not found
                    {
                        pp.rejectJoin((int)REJECTJOIN.FULL);
                        return;
                    }

                    slots[sid].computer   = 0;
                    slots[sid].color      = GetUnusedColor();
                    slots[sid].pid        = pid;
                    slots[sid].slotStatus = (byte)SlotStatus.OCCUPIED;
                    UpdateSlots();

                    var pl = new ConnectedPlayer(pp, pid, pp.joinReq.name);
                    players.Add(pl);

                    //SENDING SLOTINFOJOIN
                    x04SLOTINFOJOIN p = new x04SLOTINFOJOIN();
                    p.slots       = this.slots;
                    p.port        = 0; //(ushort)((IPEndPoint) pp.socket.Client.RemoteEndPoint).Port; //could also do pp.joinreq.port and pp.joinreq.ip
                    p.ip          = 0; //(uint)((IPEndPoint) pp.socket.Client.RemoteEndPoint).Address.Address; //this gives warning no matter what apparently.
                    p.pid         = pid;
                    p.playerSlots = (byte)gameMap.MapNumPlayers;
                    p.layoutStyle = gameMap.GetMapLayoutStyle();
                    p.randomseed  = randomseed; //This handles what race you spawn as
                    pp.player     = pl;
                    pl.queuePacket(p);

                    //SENDING MAPCHECK
                    x3dMAPCHECK MCp = new x3dMAPCHECK();
                    MCp.mapPath = this.gameMap.MapPath;
                    MCp.mapCRC  = this.gameMap.MapCRC;
                    MCp.mapInfo = this.gameMap.MapInfo;
                    MCp.mapSHA1 = this.gameMap.MapSha;
                    MCp.mapSize = this.gameMap.MapSize;
                    pl.queuePacket(MCp);

                    //SENDING FAKEHOST INFO (IF EXISTS)
                    if (fakeHostPID != 255)
                    {
                        pl.queuePacket(GetPlayerInfo(fakeHostPID));
                    }

                    var plinfo = GetPlayerInfo(pl);

                    //SENDING OTHER PLAYERS
                    foreach (var otherplayer in players)
                    {
                        if (otherplayer == pl)
                        {
                            continue;
                        }

                        pl.queuePacket(GetPlayerInfo(otherplayer));
                        otherplayer.queuePacket(plinfo);
                    }

                    //quickly throw a ping at em to get shit rollin.

                    //PING Algorithm explained in Player.cs->OnPingPacket();
                    x01PINGFROMHOST pingpkt = new x01PINGFROMHOST();
                    pingpkt.nonce = (int)(GetTimeMS() % 1000000);
                    pl.queuePacket(pingpkt);
                }
            }

            //TODO fakehost is lobby only
            if (gameState == GameState.LOBBY && fakeHostPID == 255 && players.Count < gameMap.MapNumPlayers)
            {
                CreateFakeHost();
            }


            foreach (ConnectedPlayer p in this.players)
            {
                if (p.pp.shouldDelete || p.pp.hasError || !p.pp.socket.Connected)
                {
                    continue;
                }
                p.tick();
            }

            ConnectedPlayer[] badplayers = players.Where(p => p.pp.shouldDelete || p.pp.hasError || !p.pp.socket.Connected).ToArray();
            for (var x = 0; x < badplayers.Length; x++)
            {
                RemovePlayer(badplayers[x], null);
                Console.WriteLine("*** Attempting to remove " + badplayers[x].name);
                if (this.potentialPlayers.TryTake(out badplayers[x].pp) && this.players.TryTake(out badplayers[x]))
                {
                    badplayers[x] = null;
                    Console.WriteLine("Removed player because either error,left,or dc.");
                }
                else
                {
                    Console.WriteLine("Could not remove player " + badplayers[x].name + "!");
                }
            }

            if (needToUpdateSlots && gameState == GameState.LOBBY)
            {
                //TODO(LATER)
                //implement mechanism so that download % is only constantly updated on the person downloading, and once per second on everyone else.
                // in theory could be simple as long as i make another flag "slotDLStatusUpdate" and set it to true if there's a download change
                needToUpdateSlots = false;
                Console.WriteLine("Sending updated slot info as requested");
                CleanSlots(); //make sure they are following the rules
                x09SLOTINFO sinfo = new x09SLOTINFO();
                sinfo.slots       = slots;
                sinfo.playerSlots = (byte)gameMap.MapNumPlayers;
                sinfo.layoutStyle = gameMap.GetMapLayoutStyle();
                sinfo.randomseed  = randomseed;
                SendAll(sinfo);
            }

            if (gameState == GameState.INGAME)
            {
                ProcessGameActions();
            }
        }