Beispiel #1
0
        ////////////////

        public override void OnEnterWorld(Player player)
        {
            if (player.whoAmI == this.player.whoAmI)                // Current player
            {
                var mymod = (DowsingMod)this.mod;

                if (Main.netMode != 2)                      // Not server
                {
                    if (!mymod.Config.LoadFile())
                    {
                        mymod.Config.SaveFile();
                    }
                }

                if (Main.netMode == 1)                      // Client
                {
                    DowsingNetProtocol.RequestSettingsFromServer(mymod, player);
                }
            }

            if ((((DowsingMod)this.mod).DEBUGFLAGS & 2) != 0)
            {
                int idx = this.player.FindBuffIndex(this.mod.BuffType <PsychokineticChargeDebuff>());
                if (idx != -1)
                {
                    this.player.DelBuff(idx);
                }
            }
        }
        public static void RoutePacket(DowsingMod mymod, BinaryReader reader)
        {
            DowsingNetProtocolTypes protocol = (DowsingNetProtocolTypes)reader.ReadByte();

            switch (protocol)
            {
            case DowsingNetProtocolTypes.ModSettingsRequest:
                DowsingNetProtocol.ReceiveSettingsRequestOnServer(mymod, reader);
                break;

            case DowsingNetProtocolTypes.ModSettings:
                DowsingNetProtocol.ReceiveSettingsOnClient(mymod, reader);
                break;

            case DowsingNetProtocolTypes.DowsingNpcRequest:
                DowsingNetProtocol.ReceiveDowsingNpcRequestOnServer(mymod, reader);
                break;

            case DowsingNetProtocolTypes.RequestedDowsingNpcWho:
                DowsingNetProtocol.ReceiveRequestedDowsingNpcWhoOnClient(mymod, reader);
                break;

            default:
                ErrorLogger.Log("Invalid packet protocol: " + protocol);
                break;
            }
        }
        private static void ReceiveDowsingNpcRequestOnServer(DowsingMod mymod, BinaryReader reader)
        {
            if (Main.netMode != 2)
            {
                return;
            }                                               // Server only

            int   player_who = reader.ReadInt32();
            int   npc_type   = reader.ReadInt32();
            float x          = reader.ReadSingle();
            float y          = reader.ReadSingle();

            if (player_who < 0 || player_who >= Main.player.Length || Main.player[player_who] == null)
            {
                LogHelpers.Log("ReceiveRareNpcRequestOnServer - Invalid player whoAmI. " + player_who);
                return;
            }
            if (npc_type < 0 || npc_type >= Main.npcTexture.Length)
            {
                LogHelpers.Log("ReceiveRareNpcRequestOnServer - Invalid npc_type. " + npc_type);
                return;
            }

            Player player  = Main.player[player_who];
            int    npc_who = NPC.NewNPC((int)x, (int)y, npc_type);

            DowsingNetProtocol.SendRequestedDowsingNpcFromServer(mymod, player, npc_who);
        }
        ////////////////////////////////
        // Recipients (Server)
        ////////////////////////////////

        private static void ReceiveSettingsRequestOnServer(DowsingMod mymod, BinaryReader reader)
        {
            if (Main.netMode != 2)
            {
                return;
            }                                               // Server only

            int who = reader.ReadInt32();

            if (who < 0 || who >= Main.player.Length || Main.player[who] == null)
            {
                LogHelpers.Log("ReceiveSettingsRequestOnServer - Invalid player whoAmI. " + who);
                return;
            }

            DowsingNetProtocol.SendSettingsFromServer(mymod, Main.player[who]);
        }
Beispiel #5
0
        ////////////////

        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            DowsingNetProtocol.RoutePacket(this, reader);
        }