private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID == ModManifest.UniqueID && e.Type == "PBData") { allGold message = e.ReadAs <allGold>(); allGold = message; } if (allGold != null) { if (allGold.goldList != null) { return; } else { allGold.goldList = new List <PiggyBankGold>(); Monitor.Log($"gold data list was null, creating new to prevent crash. Exit code for developer : PB-X1", LogLevel.Warn); return; } } else { allGold = new allGold(new List <PiggyBankGold>()); Monitor.Log($"gold data was null, new data set created to prevent crash. Exit code for developer : PB-X2", LogLevel.Error); return; } }
private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID == this.ModManifest.UniqueID && e.Type == "IdleMessage") { IdleMessage message = e.ReadAs <IdleMessage>(); // handle message fields here if (CheckIdle() && !message.Idle) { _peers[e.FromPlayerID] = message.Idle; if (!CheckIdle()) { showIdle = false; NotifyFarmersIdle(showIdle); } } else if (!CheckIdle() && message.Idle) { _peers[e.FromPlayerID] = message.Idle; if (CheckIdle()) { showIdle = true; NotifyFarmersIdle(showIdle); } } _peers[e.FromPlayerID] = message.Idle; } if (e.FromModID == this.ModManifest.UniqueID && e.Type == "ShowIdleMessage" && !Context.IsMainPlayer) { ShowIdleMessage message = e.ReadAs <ShowIdleMessage>(); showIdle = message.Idle; } }
//Runs when a mod sends a message to us internal static void ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID != ModEntry.Helper.Multiplayer.ModID || e.Type != Multiplayer.TogglePacket.StringType) // This isn't from our mod or a packet we know how to handle { return; } }
/// <summary> /// Handles recieving the data from another player. /// </summary> /// <param name="e">Event args.</param> internal static void RecieveData(ModMessageReceivedEventArgs e) { if (e.Type is RecieveDataValue) { data = e.ReadAs <VolcanoData>(); } }
private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID == ModManifest.UniqueID && e.Type == "SyncedLocationData") { syncedLocationData = e.ReadAs <SyncedNpcLocationData>(); } }
//Listen for the message from host player private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID == this.ModManifest.UniqueID && e.Type == "StartBirthdayEvent") { // In case they already have the birthday email, remove it if (Game1.player.mailReceived.Contains("WizardBirthdayMail")) { Game1.player.mailReceived.Remove("WizardBirthdayMail"); } //Create the letter Helper.Content.AssetEditors.Add(new BirthdayLetter()); //Send the letter for tomorrow Game1.addMailForTomorrow("WizardBirthdayMail"); //This will start the birthday in the next morning this.helper.Events.GameLoop.DayStarted += this.OnDayStarted; //Set the weather for tomorrow to sunny :D Game1.weatherForTomorrow = 4; this.Monitor.Log("Received orbital event message.", LogLevel.Debug); } }
/// <summary>Raised after a mod message is received over the network.</summary> private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID == ModManifest.UniqueID) { if (e.Type == saveDataRefreshedMessage) { // Receive the save data modSaveData = e.ReadAs <ModSaveData>(); // Refresh the furnace data InitializeFurnaceControllers(false); // If we have a menu open and we're looking at a furnace, the menu is most likely the output menu. Redraw it! if (Game1.activeClickableMenu != null && currentlyLookingAtFurnace != -1) { DrawOutputMenu(furnaces[GetIndexOfFurnaceControllerWithTag(currentlyLookingAtFurnace)]); } UpdateTextures(); UpdateFurnaceLights(); } else if (e.Type == requestSaveData) { RequestSaveData request = e.ReadAs <RequestSaveData>(); Helper.Multiplayer.SendMessage <ModSaveData>(modSaveData, saveDataRefreshedMessage, new string[] { ModManifest.UniqueID }, new long[] { request.PlayerID }); } } }
private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID != this.ModManifest.UniqueID) { return; } switch (e.Type) { case nameof(DepartureMessage): DepartureMessage departureMessage = e.ReadAs <DepartureMessage>(); mainDeckhand = Game1.getAllFarmers().First(f => f.UniqueMultiplayerID == departureMessage.MainDeckhand); trawlerObject.TriggerDepartureEvent(); break; case nameof(TrawlerEventMessage): TrawlerEventMessage eventMessage = e.ReadAs <TrawlerEventMessage>(); UpdateLocalTrawlerMap(eventMessage.EventType, eventMessage.Tile, eventMessage.IsRepairing); break; case nameof(TrawlerSyncMessage): TrawlerSyncMessage syncMessage = e.ReadAs <TrawlerSyncMessage>(); SyncLocalTrawlerMap(syncMessage.SyncType, syncMessage.Quantity); break; case nameof(TrawlerNotificationMessage): TrawlerNotificationMessage notificationMessage = e.ReadAs <TrawlerNotificationMessage>(); _activeNotification = notificationMessage.Notification; break; } }
/// <inheritdoc cref="IMultiplayerEvents.ModMessageReceived"/> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void OnModMessageReceived(object?sender, ModMessageReceivedEventArgs e) { // tractor request from a farmhand if (e.Type == this.RequestTractorMessageID && Context.IsMainPlayer && e.FromModID == this.ModManifest.UniqueID) { Farmer player = Game1.getFarmer(e.FromPlayerID); if (player is { IsMainPlayer : false })
private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { //Monitor.Log($"Got message: {e.Type}", LogLevel.Debug); if (e.FromModID != this.ModManifest.UniqueID) { return; } if (e.Type == "UpdateDeliveryOptions") { SyncDataModel message = e.ReadAs <SyncDataModel>(); DeliveryChest dchest = GetDeliveryChestFromMessage(message); if (dchest != null) { //Monitor.Log($"Send:{string.Join(", ", message.DeliveryOptions.Send)}", LogLevel.Debug); dchest.DeliveryOptions.Set(message.DeliveryOptions); if (this.CurrentOverlay != null) { this.CurrentOverlay.ResetEdit(); } } } else if (e.Type == "RequestDeliveryOptions") { SerializableChestLocation message = e.ReadAs <SerializableChestLocation>(); DeliveryChest dchest = GetDeliveryChestFromMessage(message); if (dchest != null) { Helper.Multiplayer.SendMessage(new SyncDataModel(dchest), "UpdateDeliveryOptions", modIDs: new[] { e.FromModID }, playerIDs: new[] { e.FromPlayerID }); } } }
private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID == ModHelper.Multiplayer.ModID && e.Type == MultiplayerSupport.FSTRING_SendBirthdayMessageToOthers) { string message = e.ReadAs <string>(); Game1.hudMessages.Add(new HUDMessage(message, 1)); } if (e.FromModID == ModHelper.Multiplayer.ModID && e.Type == MultiplayerSupport.FSTRING_SendBirthdayInfoToOthers) { KeyValuePair <long, PlayerData> message = e.ReadAs <KeyValuePair <long, PlayerData> >(); if (!this.othersBirthdays.ContainsKey(message.Key)) { this.othersBirthdays.Add(message.Key, message.Value); MultiplayerSupport.SendBirthdayInfoToConnectingPlayer(e.FromPlayerID); Monitor.Log("Got other player's birthday data from: " + Game1.getFarmer(e.FromPlayerID).name); } else { //Brute force update birthday info if it has already been recevived but dont send birthday info again. this.othersBirthdays.Remove(message.Key); this.othersBirthdays.Add(message.Key, message.Value); Monitor.Log("Got other player's birthday data from: " + Game1.getFarmer(e.FromPlayerID).name); } } }
private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (Context.IsWorldReady) { overlay.Value.OnModMessageReceived(sender, e); } }
public static void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (Game1.IsMasterGame && e.Type == "authRequest") { Mod.instance.Monitor.Log("Starbot authorization requested by client. Approving..."); //listen for authorization requests Dictionary <string, HashSet <string> > response = null; if (MapConnections.Count > 0) { //host bot is active, use existing cache response = MapConnections; } else { response = BuildRouteCache(); } Mod.instance.Helper.Multiplayer.SendMessage <Dictionary <string, HashSet <string> > >(response, "authResponse"); } else if (!Game1.IsMasterGame && e.Type == "authResponse") { //listen for authorization responses MapConnections = e.ReadAs <Dictionary <string, HashSet <string> > >(); Mod.instance.Monitor.Log("Starbot authorization request was approved by server."); Mod.instance.Monitor.Log("Server offered routing data for " + MapConnections.Count + " locations."); Ready = true; } else if (e.Type == "taskAssigned") { string task = e.ReadAs <string>(); Mod.instance.Monitor.Log("Another player has taken task: " + task); Core.ObjectivePool.RemoveAll(x => x.UniquePoolId == task); } }
/// <summary>Tasks performed when a mod message is received.</summary> private void ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (Context.IsMainPlayer != true) { return; } //if the player using this mod is a multiplayer farmhand, don't do anything; most of this mod's functions should be limited to the host player if (e.FromModID != ModManifest.UniqueID) { return; } //if this message is from another mod, don't do anything //handle SavedObject messages if (e.Type.Equals("SavedObject", StringComparison.OrdinalIgnoreCase)) { SavedObject save = e.ReadAs <SavedObject>(); //get the saved object /* * NOTE: This is a messy solution to saving objects that weren't generated directly by a FarmConfig, which means they aren't associated with a SavedObjects list. * For now, the objects will be added to the first available FarmData entry and forced to expire overnight (preventing them actually being written to a file). */ save.DaysUntilExpire = 1; //set the object to expire overnight Utility.FarmDataList[0].Save.SavedObjects.Add(save); //store it in the first listed FarmData } }
private static void FarmhandDonated(ModMessageReceivedEventArgs e) { if (!Context.IsMainPlayer) { return; } string fishName = e.ReadAs <string>(); string donatedFlag = GetDonatedMailFlag(fishName); MasterPlayerMail.Add(donatedFlag); string numDonated = $"AquariumFishDonated:{GetNumDonatedFish()}"; MasterPlayerMail.Add(numDonated); if (ModEntry.Data.ConversationTopicsOnDonate.Contains(fishName)) { foreach (var farmer in Game1.getAllFarmers()) { if (farmer.activeDialogueEvents.ContainsKey(donatedFlag)) { farmer.activeDialogueEvents[donatedFlag] = 3; } else { farmer.activeDialogueEvents.Add(donatedFlag, 3); } } } }
private void OnModMessageReceived(object o, ModMessageReceivedEventArgs e) { switch (e.Type) { case "Su226.AnySave.RequestRestoreFarmer": FarmerData data = M.Api.GetAndClearPlayerData(e.FromPlayerID); if (data != null) { Monitor.Log(string.Format("Send player data {0}", e.FromPlayerID)); Helper.Multiplayer.SendMessage( data, "Su226.AnySave.RestoreFarmer", new string[] { e.FromModID }, new long[] { e.FromPlayerID } ); } else { Monitor.Log(string.Format("Can't find player {0}", e.FromPlayerID)); } break; case "Su226.AnySave.RestoreFarmer": Monitor.Log(string.Format("Received player data from host.")); M.Api.RestoreCurrentPlayer(e.ReadAs <FarmerData>()); break; } }
/// <summary>Raised after a mod message is received over the network.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID != this.Helper.Multiplayer.ModID) { return; } // Upon receiving a door state requests as the host with the current state of the doors. if (e.Type == nameof(DoorStateRequest) && Context.IsMainPlayer) { DoorStateRequest request = e.ReadAs <DoorStateRequest>(); this.Helper.Multiplayer.SendMessage(new DoorStateReply(request.LocationName, this.manager.GetDoorStatesInLocation(request.LocationName)), nameof(DoorStateReply), new[] { this.Helper.Multiplayer.ModID }, new[] { e.FromPlayerID }); } // Upon receiving a door state reply as a farmhand, update the state of the doors. if (e.Type == nameof(DoorStateReply) && !Context.IsMainPlayer) { DoorStateReply reply = e.ReadAs <DoorStateReply>(); this.manager.SetDoorStates(reply.LocationName, reply.DoorStates); } // Upon receiving a door toggle, update the door if the location is loaded. if (e.Type == nameof(DoorToggle)) { DoorToggle toggle = e.ReadAs <DoorToggle>(); if (Context.IsMainPlayer || toggle.LocationName == Utils.GetLocationName(Game1.currentLocation)) { this.manager.ToggleDoor(toggle.LocationName, toggle.Position, toggle.StateBeforeToggle); } } }
/// <inheritdoc cref="IMultiplayerEvents.ModMessageReceived"/> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void OnModMessageReceived(object?sender, ModMessageReceivedEventArgs e) { // update automation if chest options changed if (Context.IsMainPlayer && e.FromModID == "Pathoschild.ChestsAnywhere" && e.Type == nameof(AutomateUpdateChestMessage)) { var message = e.ReadAs <AutomateUpdateChestMessage>(); var location = message.LocationName != null ? Game1.getLocationFromName(message.LocationName) : null; var player = Game1.getFarmer(e.FromPlayerID); string label = player != Game1.MasterPlayer ? $"{player.Name}/{e.FromModID}" : e.FromModID; if (location != null) { this.Monitor.Log($"Received chest update from {label} for chest at {message.LocationName} ({message.Tile}), updating machines."); this.MachineManager.QueueReload(location); } else { this.Monitor.Log($"Received chest update from {label} for chest at {message.LocationName} ({message.Tile}), but no such location was found."); } } }
/// <summary> /// Handles the event raised after a mod message is received /// </summary> /// <param name="sender">The sender of the ModMessageReceived event</param> /// <param name="args">Event arguments for the ModMessageReceived event</param> public void OnModMessageReceived(object sender, ModMessageReceivedEventArgs args) { Message message = args.ReadAs <Message>(); ReceivedMessages.TryAdd(args.Type, new List <Message>()); ReceivedMessages[args.Type].Add(message); }
private void OnMultiplayerPacket(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID != Helper.Multiplayer.ModID) { return; } if (!Context.IsWorldReady) { return; //don't pick locks on the title screen } string key = e.ReadAs <string>(); if (!LockCache.Contains(key)) { string[] split = key.Split('^'); string lockType = split[0]; string location = split[1]; int x = int.Parse(split[2]); int y = int.Parse(split[3]); if (location == Game1.currentLocation.NameOrUniqueName) { Game1.playSound("stoneCrack"); } Game1.playSound("axchop"); if (lockType != "SkullDoor") { LockCache.Add(key); } if (lockType == "Door") { Game1.getLocationFromName(location).map.GetLayer("Back").Tiles[x, y].Properties.Remove("TouchAction"); } } }
private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID != ModEntry.Instance.PongId) { return; } if (e.Type == typeof(GameState).Name && !this.isLeader) { GameState newState = e.ReadAs <GameState>(); double diff = GetTimestamp() - newState.CurrentTime; newState.BallVelocityState.Invert(); newState.BallPositionState.Invert(); newState.PaddlePositionState.Invert(); this.state.SetState(newState); //diff milli seconds, 60 frames per second -> need to run diff * 60 //for (int i = 0; i < (diff * 60) / 1000; i++) // this.Update(); //if ((int)((diff * 60) / 1000) > 0) // ModEntry.Instance.Monitor.Log($"Follower updated {(int)((diff * 60) / 1000)} times"); } else if (e.Type == typeof(PositionState).Name && this.isLeader) { PositionState newState = e.ReadAs <PositionState>(); newState.Invert(); this.followerPaddlePosition.SetState(newState); } }
public void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { #if DEBUG ModEntry.ModMonitor.Log($"Received message.\n\tFromPlayer: \"{e.FromPlayerID}\"\n\tFromMod: \"{e.FromModID}\"\n\tType: \"{e.Type}\"", LogLevel.Trace); #endif Type messageType = typeof(EmoteMessage); if (e.FromModID != helper.ModRegistry.ModID || e.Type != messageType.ToString()) { return; } EmoteMessage message = e.ReadAs <EmoteMessage>(); switch (message.EmoteSourceType) { case CharacterType.Farmer: if (long.TryParse(message.EmoteSourceId, out long farmerId)) { Farmer farmer = Game1.getFarmer(farmerId); if (farmer != null) { FarmerPatch.DoEmotePatch.Instance.PostfixEnabled = false; farmer.IsEmoting = false; farmer.doEmote(message.EmoteIndex); FarmerPatch.DoEmotePatch.Instance.PostfixEnabled = true; } } break; case CharacterType.NPC: NPC npc = Game1.getCharacterFromName(message.EmoteSourceId); if (npc != null && !npc.IsEmoting) { CharacterPatch.DoEmotePatch.Instance.PostfixEnabled = false; npc.IsEmoting = false; npc.doEmote(message.EmoteIndex); CharacterPatch.DoEmotePatch.Instance.PostfixEnabled = true; } break; case CharacterType.FarmAnimal: if (long.TryParse(message.EmoteSourceId, out long farmAnimalId)) { FarmAnimal farmAnimal = Game1.getFarm().getAllFarmAnimals().FirstOrDefault(x => x?.myID.Value == farmAnimalId); if (farmAnimal != null && !farmAnimal.IsEmoting) { CharacterPatch.DoEmotePatch.Instance.PostfixEnabled = false; farmAnimal.IsEmoting = false; farmAnimal.doEmote(message.EmoteIndex); CharacterPatch.DoEmotePatch.Instance.PostfixEnabled = true; } } break; case CharacterType.Unknown: default: break; } }
private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { //Monitor.Log($"Received mod message: {e.FromModID}:{e.Type}:{e.ReadAs<string>()}", LogLevel.Info); if (e.FromModID == this.ModManifest.UniqueID) { if (e.Type == MESSAGE_SPRINT_SPEED) { this.actualSprintSpeed = e.ReadAs <int>(); } if (e.Type == MESSAGE_SPRINT_STAMINA) { this.actualStaminaDrain = e.ReadAs <float>(); } if (e.Type == MESSAGE_ENABLE_FLOOR) { this.enableFloorSpeed = e.ReadAs <bool>(); } if (e.Type == MESSAGE_FLOOR_SPEED) { this.additionalFloorSpeed = e.ReadAs <int>(); } } }
private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (NpcMarkers == null) { return; } if (e.FromModID == ModManifest.UniqueID && e.Type == "SyncedLocationData") { var message = e.ReadAs <SyncedLocationData>(); foreach (var marker in NpcMarkers) { if (message.SyncedLocations.TryGetValue(marker.Npc.Name, out var npcLoc)) { marker.SyncedLocationName = npcLoc.LocationName; if (!marker.IsHidden) { var mapLocation = LocationToMap(npcLoc.LocationName, npcLoc.TileX, npcLoc.TileY); marker.MapLocation = new Vector2(mapLocation.X - 16, mapLocation.Y - 15); } } else { marker.MapLocation = new Vector2(-1000, -1000); } } } }
/****************************************************************************** * Multiplayer Routing *****************************************************************************/ private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { // Message from host to targeted Peer to assign PlayerIndex if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "PlayerIndex") { this.PlayerIndex = e.ReadAs <int>(); } // Warps are global, so they are to be handled by the host only else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "AddWarp") { if (Context.IsMainPlayer) { AddWarp(e.ReadAs <PortalPosition>()); } } else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "RemoveWarp") { if (Context.IsMainPlayer) { RemoveWarp(e.ReadAs <PortalPosition>()); } } // Portal Sprites are local so all players need to handle the other players' else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "AddPortalSprite") { PortalSprites.AddPortalSprite(e.ReadAs <PortalPosition>()); } else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "RemovePortalSprite") { PortalSprites.RemovePortalSprite(e.ReadAs <PortalPosition>()); } // keeping the logic for all the portal guns the same else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "UpdateAddPortal") { PortalGuns.AddPortal(e.ReadAs <PortalPosition>()); } else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "UpdateRemovePortals") { PortalGuns.RemovePortals(e.ReadAs <int>()); } else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "GetActivePortalSprites") { SendActivePortalSprites(e.FromPlayerID); } else if (e.FromModID == "JoshJKe.PortalGun" && e.Type == "SendActivePortalSprites") { SetActivePortalSprites(e.ReadAs <List <PortalPosition> >()); } }
/// <summary> /// Used by the peers to recieve and set the value for Utilities.Utilities.SaveFolderName field /// </summary> /// <param name="sender">Sender of the event</param> /// <param name="e">Contains all the data/args of the event</param> public static void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID == Utilities.Data.Helper.ModRegistry.ModID && e.Type == "SaveFolderName") { SaveFolderNameModel message = e.ReadAs <SaveFolderNameModel>(); Utilities.Data.SaveFolderName = message.SaveFolderName; } }
private void ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { // read list if (e.FromModID == "Jessebot.BeyondTheValley" && e.Type == "DeletedTiles") { TileActionFramework.mpInputArgs = e.ReadAs <List <string> >(); } }
/************** * REGION MULTIPLAYER * ***********/ private void OnModMessageRecieved(object?sender, ModMessageReceivedEventArgs e) { if (e.FromModID != ModEntry.UNIQUEID) { return; } VolcanoChestAdjuster.RecieveData(e); }
private void ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { // read list if (e.FromModID == this.ModManifest.UniqueID && e.Type == "DeletedTiles") { _TileActionFramework.MPInputArgs = e.ReadAs <List <string> >(); } }
/// <summary> /// Updates entry for Pam's schedule from a multiplayer message. /// </summary> /// <param name="e">arguments.</param> internal static void UpdateFromMessage(ModMessageReceivedEventArgs e) { if (e.FromModID == Globals.Manifest.UniqueID && e.Type == SCHEDULEMESSAGE) { PamsSchedule = e.ReadAs <string>(); Globals.ModMonitor.Log($"Recieved Pam's schedule {PamsSchedule}", LogLevel.Debug); } }