public void Awake() { instance = this; RegisterCallbacks(); InitializePacketTools(); }
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"); } }
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(); }
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; } }
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; } }
/* * 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); }
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; }
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."); } }
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."); } }
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(); }
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; } } }
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); }
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."); } }
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}"); }