private void SyncSavingToClient() { lock (this) { NetMessage.SendData(MessageID.SyncPlayer, -1, -1, NetworkText.FromLiteral(Main.player[playerID].name), playerID, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerControls, -1, -1, NetworkText.Empty, playerID, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerHealth, -1, -1, NetworkText.Empty, playerID); NetMessage.SendData(MessageID.PlayerPvP, -1, -1, NetworkText.Empty, playerID, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerTeam, -1, -1, NetworkText.Empty, playerID, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerMana, -1, -1, NetworkText.Empty, playerID); NetMessage.SendData(MessageID.PlayerBuffs, -1, -1, NetworkText.Empty, playerID, 0f, 0f, 0f, 0, 0, 0); Main.player[playerID].trashItem = new Item(); SyncItemData(); PlayerHooks.SyncPlayer(Main.player[playerID], -1, -1, false); } }
private static void SyncOnePlayer(int plr, int toWho, int fromWho) { var active = 0; if (Main.player[plr].active) { active = 1; } if (Netplay.Clients[plr].State == 10) { var name = Main.player[plr].name; var player = ServerSideCharacter2.PlayerCollection.Get(name); player.SetID(plr); player.ApplyToPlayer(); NetMessage.SendData(MessageID.PlayerActive, toWho, fromWho, null, plr, active, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.SyncPlayer, toWho, fromWho, null, plr, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerControls, toWho, fromWho, null, plr, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerHealth, toWho, fromWho, null, plr); NetMessage.SendData(MessageID.PlayerPvP, toWho, fromWho, null, plr, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerTeam, toWho, fromWho, null, plr, 0f, 0f, 0f, 0, 0, 0); NetMessage.SendData(MessageID.PlayerMana, toWho, fromWho, null, plr); NetMessage.SendData(MessageID.PlayerBuffs, toWho, fromWho, null, plr, 0f, 0f, 0f, 0, 0, 0); if (toWho == -1) { player.IsLogin = false; player.ClearAllBuffs(); player.Lock(); player.SyncUnionInfo(); player.SendMailList(); MessageSender.SendWelcomeMessage(plr, player.HasPassword ? GameLanguage.GetText("welcomeold") : GameLanguage.GetText("welcomenew")); MessageSender.SyncRegionsToClient(plr); if (!player.InRegion || player.CurrentRegion.PVP == JsonData.PVPMode.Normal) { if (ServerSideCharacter2.Config.PvpMode == JsonData.PVPMode.Always) { player.PrototypePlayer.hostile = true; NetMessage.SendData(MessageID.PlayerPvP, -1, -1, NetworkText.FromLiteral(""), player.PrototypePlayer.whoAmI); } } } Main.player[plr].trashItem = new Item(); for (var i = 0; i < 59; i++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, NetworkText.FromLiteral(Main.player[plr].inventory[i].Name), plr, i, Main.player[plr].inventory[i].prefix, 0f, 0, 0, 0); } for (var j = 0; j < Main.player[plr].armor.Length; j++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, NetworkText.FromLiteral(Main.player[plr].armor[j].Name), plr, (59 + j), Main.player[plr].armor[j].prefix, 0f, 0, 0, 0); } for (var k = 0; k < Main.player[plr].dye.Length; k++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, NetworkText.FromLiteral(Main.player[plr].dye[k].Name), plr, (58 + Main.player[plr].armor.Length + 1 + k), Main.player[plr].dye[k].prefix, 0f, 0, 0, 0); } for (var l = 0; l < Main.player[plr].miscEquips.Length; l++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, NetworkText.Empty, plr, 58 + Main.player[plr].armor.Length + Main.player[plr].dye.Length + 1 + l, Main.player[plr].miscEquips[l].prefix, 0f, 0, 0, 0); } for (var m = 0; m < Main.player[plr].miscDyes.Length; m++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, NetworkText.Empty, plr, 58 + Main.player[plr].armor.Length + Main.player[plr].dye.Length + Main.player[plr].miscEquips.Length + 1 + m, Main.player[plr].miscDyes[m].prefix, 0f, 0, 0, 0); } for (var i = 0; i < Main.player[plr].bank.item.Length; i++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, null, plr, 58 + Main.player[plr].armor.Length + Main.player[plr].dye.Length + Main.player[plr].miscEquips.Length + Main.player[plr].miscDyes.Length + 1 + i, Main.player[plr].bank.item[i].prefix, 0f, 0, 0, 0); } for (var i = 0; i < Main.player[plr].bank2.item.Length; i++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, null, plr, 58 + Main.player[plr].armor.Length + Main.player[plr].dye.Length + Main.player[plr].miscEquips.Length + Main.player[plr].miscDyes.Length + Main.player[plr].bank.item.Length + 1 + i, Main.player[plr].bank2.item[i].prefix, 0f, 0, 0, 0); } NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, null, plr, 58 + Main.player[plr].armor.Length + Main.player[plr].dye.Length + Main.player[plr].miscEquips.Length + Main.player[plr].bank.item.Length + Main.player[plr].bank2.item.Length + 1, Main.player[plr].trashItem.prefix); for (var i = 0; i < Main.player[plr].bank3.item.Length; i++) { NetMessage.SendData(MessageID.SyncEquipment, toWho, fromWho, null, plr, 58 + Main.player[plr].armor.Length + Main.player[plr].dye.Length + Main.player[plr].miscEquips.Length + Main.player[plr].bank.item.Length + Main.player[plr].bank2.item.Length + 2 + i, Main.player[plr].bank2.item[i].prefix, 0f, 0, 0, 0); } PlayerHooks.SyncPlayer(Main.player[plr], toWho, fromWho, false); if (!Netplay.Clients[plr].IsAnnouncementCompleted) { Netplay.Clients[plr].IsAnnouncementCompleted = true; if (Main.dedServ) { Console.WriteLine(Main.player[plr].name + GameLanguage.GetText("entergame")); } } } else { active = 0; NetMessage.SendData(MessageID.PlayerActive, -1, plr, NetworkText.Empty, plr, active, 0f, 0f, 0, 0, 0); if (Netplay.Clients[plr].IsAnnouncementCompleted) { Netplay.Clients[plr].IsAnnouncementCompleted = false; NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(Netplay.Clients[plr].Name + GameLanguage.GetText("leavegame")), new Color(255, 255, 240, 20), plr); if (Main.dedServ) { Console.WriteLine(Netplay.Clients[plr].Name + GameLanguage.GetText("leavegame")); } Netplay.Clients[plr].Name = "Anonymous"; } } }