示例#1
0
        public void Awake()
        {
            instance = this;

            RegisterCallbacks();
            InitializePacketTools();
        }
示例#2
0
 public void ReadLoadPacket(BinaryReader reader, CSteamID sent)
 {
     if (reader.ReadBoolean())
     {
         if (!ingamePlayers.Contains(sent.m_SteamID))
         {
             ingamePlayers.Add(sent.m_SteamID);
         }
         if (!roomDict.ContainsKey(sent.m_SteamID))
         {
             roomDict.Add(sent.m_SteamID, new List <string>());
         }
         MonklandSteamManager.Log("[World] Incomming game start packet: " + ingamePlayers.Count + " players ingame");
         if (isManager && gameRunning)
         {
             SyncCycle(sent);
         }
     }
     else
     {
         if (ingamePlayers.Contains(sent.m_SteamID))
         {
             ingamePlayers.Remove(sent.m_SteamID);
         }
         if (roomDict.ContainsKey(sent.m_SteamID))
         {
             roomDict.Remove(sent.m_SteamID);
         }
         MonklandSteamManager.Log("[World] Incomming game end packet: " + ingamePlayers.Count + " players ingame");
     }
 }
示例#3
0
        public void DeactivateRoom(int roomName)
        {
            MonklandSteamManager.Log("[World] Sending room deactivate: " + roomName);
            //if (string.IsNullOrEmpty(roomName)) { return; }

            if (!roomDict.ContainsKey(playerID))
            {
                roomDict.Add(playerID, new List <int>());
            }
            if (roomDict[playerID].Contains(roomName))

            {
                roomDict[playerID].Remove(roomName);
            }

            MonklandSteamManager.DataPacket packet = MonklandSteamManager.instance.GetNewPacket(WORLD_CHANNEL, WorldHandler);
            BinaryWriter writer = MonklandSteamManager.instance.GetWriterForPacket(packet);

            //Write message type
            writer.Write(Convert.ToByte(3));
            writer.Write(roomName);

            MonklandSteamManager.instance.FinalizeWriterToPacket(writer, packet);
            //MonklandSteamManager.instance.SendPacket(packet, (CSteamID)managerID), EP2PSend.k_EP2PSendReliable);
            MonklandSteamManager.instance.SendPacketToAll(packet, true, EP2PSend.k_EP2PSendReliable);
            CheckForCommonRooms();
        }
示例#4
0
 public void ReadRainPacket(BinaryReader reader, CSteamID sent)
 {
     this.cycleLength = reader.ReadInt32();
     this.timer       = reader.ReadInt32();
     MonklandSteamManager.Log($"[World] Incomming rain packet: {this.cycleLength}, {this.timer}");
     if (RainWorldGameHK.mainGame != null && RainWorldGameHK.mainGame.overWorld != null && RainWorldGameHK.mainGame.overWorld.activeWorld != null)
     {
         RainWorldGameHK.mainGame.overWorld.activeWorld.rainCycle.cycleLength = this.cycleLength;
         RainWorldGameHK.mainGame.overWorld.activeWorld.rainCycle.timer       = this.timer;
     }
 }
示例#5
0
 public void ReadRainPacket(BinaryReader reader, CSteamID sent)
 {
     this.cycleLength = reader.ReadInt32();
     this.timer       = reader.ReadInt32();
     MonklandSteamManager.Log("[World] Incomming rain packet: " + this.cycleLength + ", " + this.timer);
     if (patch_RainWorldGame.mainGame != null && patch_RainWorldGame.mainGame.overWorld != null && patch_RainWorldGame.mainGame.overWorld.activeWorld != null)
     {
         patch_RainWorldGame.mainGame.overWorld.activeWorld.rainCycle.cycleLength = this.cycleLength;
         patch_RainWorldGame.mainGame.overWorld.activeWorld.rainCycle.timer       = this.timer;
     }
 }
示例#6
0
        /*
         * public void PlayerKilled(ulong playerDead)
         * {
         *  MonklandSteamManager.DataPacket packet = MonklandSteamManager.instance.GetNewPacket(CHANNEL, UtilityHandler);
         *  BinaryWriter writer = MonklandSteamManager.instance.GetWriterForPacket(packet);
         *
         *  //Write message type
         *  writer.Write((byte)UtilMessageType.PlayerDead);
         *  writer.Write(playerDead);
         *
         *  MonklandSteamManager.instance.FinalizeWriterToPacket(writer, packet);
         *  MonklandSteamManager.instance.SendPacketToAll(packet, false, EP2PSend.k_EP2PSendReliable);
         *
         *  Debug.Log($"Writing packet: {packet.data}");
         * }
         */

        public void SendViolence(Creature self, BodyChunk source, Creature.DamageType type, float damage)
        {
            /*
             * Violence packet
             * packetType
             * damageType
             * sourceType (player/scav/lizard)
             * source ID
             */

            if (self == null || AbstractPhysicalObjectHK.GetField(self.abstractPhysicalObject).networkObject)
            {
                return;
            }

            // Source ID field
            MonklandSteamManager.DataPacket packet = MonklandSteamManager.instance.GetNewPacket(CHANNEL, UtilityHandler);
            BinaryWriter writer = MonklandSteamManager.instance.GetWriterForPacket(packet);

            // SourceTemplate
            byte sourceTemplate = byte.MaxValue - 1;

            try
            {
                sourceTemplate = (byte)(source.owner.abstractPhysicalObject as AbstractCreature).creatureTemplate.TopAncestor().type;
                //sourceTemplate = (byte)((source.owner as Creature).abstractCreature.creatureTemplate.type);
            }
            catch (Exception e) { Debug.Log("Error getting source type " + e.Message); }

            // SourceID
            ulong sourceID = 0;

            try
            {
                sourceID = (AbstractPhysicalObjectHK.GetField(source.owner.abstractPhysicalObject).owner);
            }
            catch { } //(Exception e) {/*Debug.Log()*/}

            // Message type
            writer.Write((byte)UtilMessageType.PlayerViolence);
            // Damage type
            writer.Write((byte)type);
            // Damage
            writer.Write((bool)(damage >= 1f));
            // Source Template
            writer.Write(sourceTemplate);
            // Source ID
            writer.Write(sourceID);

            MonklandSteamManager.Log($"[GameMNG] Sending Player Violence: Type {type}, damage {damage} Source Template {(CreatureTemplate.Type)sourceTemplate}, Source ID {sourceID}");
            MonklandSteamManager.instance.FinalizeWriterToPacket(writer, packet);
            MonklandSteamManager.instance.SendPacketToAll(packet, false, EP2PSend.k_EP2PSendReliable);
        }
示例#7
0
            public PacketChannel(string name, int channelIndex, MonklandSteamManager manager, int packetsPerUpdate = 20, int maxPackets = 100, bool priorityBased = false, bool ordered = false, bool scrapOldOrdered = false)
            {
                this.channelName  = name;
                this.channelIndex = channelIndex;
                this.manager      = manager;

                lastPacketID          = new Dictionary <ulong, uint>();
                this.packetsPerUpdate = packetsPerUpdate;
                this.isPriorityBased  = priorityBased;
                this.isOrdered        = ordered;
                this.scrapOld         = scrapOldOrdered;
                this.maxPackets       = maxPackets;
            }
示例#8
0
 public void CheckForCommonRooms()
 {
     commonRooms.Clear();
     foreach (ulong player in roomDict.Keys)
     {
         if (player != playerID && roomDict.ContainsKey(player))
         {
             foreach (int otherRoom in roomDict[player])
             {
                 if (roomDict.ContainsKey(playerID))
                 {
                     foreach (int myRoom in roomDict[playerID])
                     {
                         if (myRoom.Equals(otherRoom) /*&& !string.IsNullOrEmpty(myRoom)*/) // WHEN DOES THIS HAPPEN
                         {
                             if (!commonRooms.ContainsKey(myRoom))
                             {
                                 commonRooms.Add(myRoom, new List <ulong>());
                             }
                             if (!commonRooms[myRoom].Contains(player))
                             {
                                 commonRooms[myRoom].Add(player);
                             }
                         }
                     }
                 }
             }
         }
     }
     foreach (int roomName in commonRooms.Keys)
     {
         AbstractRoom abstractRoom = RainWorldGameHK.mainGame.world.GetAbstractRoom(roomName);
         if (abstractRoom != null && abstractRoom.realizedRoom != null)
         {
             RoomHK.MultiplayerNewToRoom(abstractRoom.realizedRoom, commonRooms[roomName]);
         }
     }
     if (MonklandSteamManager.DEBUG)
     {
         string roomlist = "";
         foreach (int room in commonRooms.Keys)
         {
             roomlist = roomlist + room + ", ";
         }
         MonklandSteamManager.Log("[World] Room Packet: Player shares " + roomlist + " rooms with other players.");
     }
 }
示例#9
0
 public void CheckForCommonRooms()
 {
     commonRooms.Clear();
     foreach (ulong player in roomDict.Keys)
     {
         if (player != playerID && roomDict.ContainsKey(player))
         {
             foreach (string otherRoom in roomDict[player])
             {
                 if (roomDict.ContainsKey(playerID))
                 {
                     foreach (string myRoom in roomDict[playerID])
                     {
                         if (myRoom.Equals(otherRoom) && myRoom != null && myRoom != "" && !myRoom.Equals(""))
                         {
                             if (!commonRooms.ContainsKey(myRoom))
                             {
                                 commonRooms.Add(myRoom, new List <ulong>());
                             }
                             if (!commonRooms[myRoom].Contains(player))
                             {
                                 commonRooms[myRoom].Add(player);
                             }
                         }
                     }
                 }
             }
         }
     }
     foreach (string roomName in commonRooms.Keys)
     {
         AbstractRoom abstractRoom = patch_RainWorldGame.mainGame.world.GetAbstractRoom(roomName);
         if (abstractRoom != null && abstractRoom.realizedRoom != null)
         {
             (abstractRoom.realizedRoom as patch_Room).MultiplayerNewToRoom(commonRooms[roomName]);
         }
     }
     if (MonklandSteamManager.DEBUG)
     {
         string roomlist = "";
         foreach (string room in commonRooms.Keys)
         {
             roomlist = roomlist + room + ", ";
         }
         MonklandSteamManager.Log("[World] Room Packet: Player shares " + roomlist + " rooms with other players.");
     }
 }
示例#10
0
        public void ReadActivateRoom(BinaryReader reader, CSteamID sent)
        {
            if (sent.m_SteamID == playerID)
            {
                return;
            }
            string roomName = reader.ReadString();

            if (!roomDict.ContainsKey(sent.m_SteamID))
            {
                roomDict.Add(sent.m_SteamID, new List <string>());
            }
            if (!roomDict[sent.m_SteamID].Contains(roomName))
            {
                roomDict[sent.m_SteamID].Add(roomName);
            }
            MonklandSteamManager.Log("[World] Incomming room activate: " + roomName);
            CheckForCommonRooms();
        }
示例#11
0
        public void GameStart()
        {
            this.sessionTotalCycles++;
            this.timer = 0;
            if (!ingamePlayers.Contains(playerID))
            {
                ingamePlayers.Add(playerID);
            }

            if (!roomDict.ContainsKey(playerID))
            {
                roomDict.Add(playerID, new List <int>());
            }

            MonklandSteamManager.Log($"[World] Sending game start packet: {ingamePlayers.Count} players ingame");
            foreach (ulong player in ingamePlayers)
            {
                MonklandSteamManager.Log(player);
            }
            gameRunning = true;
            MonklandSteamManager.DataPacket packet = MonklandSteamManager.instance.GetNewPacket(WORLD_CHANNEL, WorldHandler);
            BinaryWriter writer = MonklandSteamManager.instance.GetWriterForPacket(packet);

            //Write message type
            writer.Write(Convert.ToByte(0));
            writer.Write(true);

            MonklandSteamManager.instance.FinalizeWriterToPacket(writer, packet);
            //MonklandSteamManager.instance.SendPacket(packet, (CSteamID)managerID), EP2PSend.k_EP2PSendReliable);
            MonklandSteamManager.instance.SendPacketToAll(packet, true, EP2PSend.k_EP2PSendReliable);
            if (isManager)
            {
                foreach (ulong pl in ingamePlayers)
                {
                    if (pl != playerID)
                    {
                        SyncCycle((CSteamID)pl);
                    }
                    syncDelay = 1000;
                }
            }
        }
示例#12
0
        public void GameEnd()
        {
            if (ingamePlayers.Contains(playerID))
            {
                ingamePlayers.Remove(playerID);
            }
            MonklandSteamManager.Log($"[World] Sending game end packet: {ingamePlayers.Count} players ingame");
            roomDict.Clear();
            roomDict.Add(playerID, new List <int>());
            gameRunning = false;
            MonklandSteamManager.DataPacket packet = MonklandSteamManager.instance.GetNewPacket(WORLD_CHANNEL, WorldHandler);
            BinaryWriter writer = MonklandSteamManager.instance.GetWriterForPacket(packet);

            //Write message type
            writer.Write(Convert.ToByte(0));
            writer.Write(false);

            MonklandSteamManager.instance.FinalizeWriterToPacket(writer, packet);
            //MonklandSteamManager.instance.SendPacket(packet, (CSteamID)managerID), EP2PSend.k_EP2PSendReliable);
            MonklandSteamManager.instance.SendPacketToAll(packet, true, EP2PSend.k_EP2PSendReliable);
        }
示例#13
0
 public void CheckForCommonRooms()
 {
     commonRooms.Clear();
     foreach (ulong player in roomDict.Keys)
     {
         if (player != playerID && roomDict.ContainsKey(player))
         {
             foreach (string otherRoom in roomDict[player])
             {
                 if (roomDict.ContainsKey(playerID))
                 {
                     foreach (string myRoom in roomDict[playerID])
                     {
                         if (myRoom.Equals(otherRoom) && myRoom != null && myRoom != "" && !myRoom.Equals(""))
                         {
                             if (!commonRooms.ContainsKey(myRoom))
                             {
                                 commonRooms.Add(myRoom, new List <ulong>());
                             }
                             if (!commonRooms[myRoom].Contains(player))
                             {
                                 commonRooms[myRoom].Add(player);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (MonklandSteamManager.DEBUG)
     {
         string roomlist = "";
         foreach (string room in commonRooms.Keys)
         {
             roomlist = roomlist + ", " + room;
         }
         MonklandSteamManager.Log("Room Packet: Player shares " + roomlist + " rooms with other players.");
     }
 }
示例#14
0
        private void ReadViolence(BinaryReader br, CSteamID sentPlayer)
        {
            // Message type

            // Damage type
            Creature.DamageType type = (Creature.DamageType)br.ReadByte();
            // Lethal
            bool lethal = br.ReadBoolean();

            // Source Template
            CreatureTemplate.Type sourceTemplate = (CreatureTemplate.Type)br.ReadByte();
            // Source ID
            ulong sourceID = (ulong)br.ReadUInt64();

            if (lethal)
            {
                string message = MonklandUI.BuildDeathMessage(sentPlayer, type, sourceTemplate, sourceID);
                Debug.Log(message);
                MonklandUI.AddMessage(message, 10);
            }

            MonklandSteamManager.Log($"[GameMNG] Reading Player Violence: Damage type {type}, Source Template {sourceTemplate}, Source ID {sourceID}");
        }