public override void onPlayerJoin(PlayerLoginEvent Event) { Event.Sender.sendMessage("Welcome, " + Event.Player.Name, 255, 100, 200, 100); Item item = Registries.Item.Create("Statue"); Item.NewItem((int)Event.Player.Position.X, (int)Event.Player.Position.Y, Event.Player.Width, Event.Player.Height, item.Type); }
public void Process(int start, int length, int num, int whoAmI, byte[] readBuffer, byte bufferData) { ServerSlot slot = Netplay.slots[whoAmI]; PlayerLoginEvent loginEvent = new PlayerLoginEvent(); loginEvent.Slot = slot; loginEvent.Sender = Main.players[whoAmI]; Program.server.PluginManager.processHook(Plugin.Hooks.PLAYER_PRELOGIN, loginEvent); if ((loginEvent.Cancelled || loginEvent.Action == PlayerLoginAction.REJECT) && (slot.state & SlotState.DISCONNECTING) == 0) { slot.Kick ("Disconnected by server."); return; } String clientName = slot.remoteAddress.Split(':')[0]; // // if (Program.server.BanList.containsException(clientName)) // { // slot.Kick ("You are banned from this Server."); // return; // } if (Program.properties.UseWhiteList && !Program.server.WhiteList.containsException(clientName)) { slot.Kick ("You are not on the WhiteList."); return; } if (slot.state == SlotState.CONNECTED) { String version = Encoding.ASCII.GetString(readBuffer, start + 1, length - 1); #if TEST_COMPRESSION if ((version == "Terraria" + Statics.CURRENT_TERRARIA_RELEASE + "undead")) { ProgramLog.Debug.Log ("{0} @ {1}: Undead's client detected.", slot.remoteAddress, whoAmI); slot.conn.myClient = true; } else #endif if (!(version == "Terraria" + Statics.CURRENT_TERRARIA_RELEASE)) { if (version.Length > 30) version = version.Substring (0, 30); ProgramLog.Debug.Log ("Client version string: {0}", version); slot.Kick (string.Concat ("This server requires Terraria ", Program.VERSION_NUMBER)); return; } if (Netplay.password == null || Netplay.password == "") { slot.state = SlotState.ACCEPTED; NetMessage.SendData(3, whoAmI); return; } slot.state = SlotState.SERVER_AUTH; NetMessage.SendData(37, whoAmI); } }
public void Process(int start, int length, int num, int whoAmI, byte[] readBuffer, byte bufferData) { String password = Encoding.ASCII.GetString(readBuffer, num, length - num + start); var slot = Netplay.slots[whoAmI]; if (slot.state == SlotState.SERVER_AUTH) { if (password == Netplay.password) { slot.state = SlotState.ACCEPTED; NetMessage.SendData (3, whoAmI); return; } slot.Kick ("Incorrect server password."); } else if (slot.state == SlotState.PLAYER_AUTH) { var name = Main.players[whoAmI].Name ?? ""; var loginEvent = new PlayerLoginEvent(); loginEvent.Slot = slot; loginEvent.Sender = Main.players[whoAmI]; loginEvent.Password = password; Program.server.PluginManager.processHook (Plugin.Hooks.PLAYER_AUTH_REPLY, loginEvent); if (loginEvent.Action == PlayerLoginAction.REJECT) { if ((slot.state & SlotState.DISCONNECTING) == 0) slot.Kick ("Incorrect password for user: "******"")); } else if (loginEvent.Action == PlayerLoginAction.ASK_PASS) { NetMessage.SendData (37, whoAmI, -1, ""); } else // PlayerLoginAction.ACCEPT { slot.state = SlotState.SENDING_WORLD; NetMessage.SendData (4, -1, whoAmI, name, whoAmI); // broadcast player data now // replay packets from side buffer var buf = NetMessage.buffer[whoAmI]; NetMessage.CheckBytes (whoAmI, buf.sideBuffer, ref buf.sideBufferBytes, ref buf.sideBufferMsgLen); buf.ResetSideBuffer (); NetMessage.SendData (7, whoAmI); // continue with world data } } }
public void Process(int start, int length, int num, int whoAmI, byte[] readBuffer, byte bufferData) { ServerSock serverSock = Netplay.serverSock[whoAmI]; PlayerLoginEvent loginEvent = new PlayerLoginEvent(); loginEvent.Socket = serverSock; loginEvent.Sender = Main.players[whoAmI]; Program.server.getPluginManager().processHook(Plugin.Hooks.PLAYER_PRELOGIN, loginEvent); if (loginEvent.Cancelled) { NetMessage.SendData(2, whoAmI, -1, "Disconnected By Server."); return; } String clientName = serverSock.tcpClient.Client.RemoteEndPoint.ToString().Split(':')[0]; if (Program.server.BanList.containsException(clientName)) { NetMessage.SendData(2, whoAmI, -1, "You are banned from this Server."); return; } if (Program.properties.UseWhiteList && !Program.server.WhiteList.containsException(clientName)) { NetMessage.SendData(2, whoAmI, -1, "You are not on the WhiteList."); return; } if (serverSock.state == 0) { string version = Encoding.ASCII.GetString(readBuffer, start + 1, length - 1); if (!(version == "Terraria" + Statics.CURRENT_RELEASE)) { NetMessage.SendData(2, whoAmI, -1, "You are not using the same version as this Server."); return; } if (Netplay.password == null || Netplay.password == "") { serverSock.state = 1; NetMessage.SendData(3, whoAmI); return; } serverSock.state = -1; NetMessage.SendData(37, whoAmI); } }
public override void onPlayerJoin(PlayerLoginEvent Event) { try { user = Event.Sender.Name.ToString().Replace(" ", "").ToLower(); FileStream dataread = new FileStream(playerFolder + user + ".dat", FileMode.Open); BinaryReader datareader = new BinaryReader(dataread); userbalance = datareader.ReadInt32(); dataread.Close(); datareader.Close(); } catch { userbalance = 0; user = Event.Sender.Name.ToString().Replace(" ", "").ToLower(); string usernew = Event.Player.Name.ToString(); NetMessage.SendData(25, -1, -1, "New vCoin account created for " + usernew + ".", 255, 0, 255, 255); FileStream datawrite = new FileStream(playerFolder + user + ".dat", FileMode.Create, FileAccess.ReadWrite); BinaryWriter datawriter = new BinaryWriter(datawrite); datawriter.Write(userbalance); datawrite.Close(); datawriter.Close(); } }
public void Process(int start, int length, int num, int whoAmI, byte[] readBuffer, byte bufferData) { int playerIndex = whoAmI; var slot = Netplay.slots[whoAmI]; if (playerIndex == Main.myPlayer) { return; } int hairId = (int)readBuffer[start + 2]; if (hairId >= MAX_HAIR_ID) { hairId = 0; } Player player = Main.players[playerIndex]; player.hair = hairId; player.whoAmi = playerIndex; num += 2; num = setColor(player.hairColor, num, readBuffer); num = setColor(player.skinColor, num, readBuffer); num = setColor(player.eyeColor, num, readBuffer); num = setColor(player.shirtColor, num, readBuffer); num = setColor(player.underShirtColor, num, readBuffer); num = setColor(player.pantsColor, num, readBuffer); num = setColor(player.shoeColor, num, readBuffer); player.hardCore = (readBuffer[num++] != 0); player.Name = Encoding.ASCII.GetString(readBuffer, num, length - num + start).Trim(); if (slot.state < SlotState.PLAYING) { int count = 0; foreach(Player otherPlayer in Main.players) { if (count++ != playerIndex && player.Name.Equals(otherPlayer.Name) && slot.state >= SlotState.CONNECTED) { slot.Kick (player.Name + " is already on this server."); return; } } } if (player.Name.Length > 20) { slot.Kick ("Name is too long."); return; } if (player.Name == "") { slot.Kick ("Empty name."); return; } Netplay.slots[whoAmI].oldName = player.Name; Netplay.slots[whoAmI].name = player.Name; var loginEvent = new PlayerLoginEvent(); loginEvent.Slot = slot; loginEvent.Sender = player; Program.server.PluginManager.processHook (Plugin.Hooks.PLAYER_AUTH_QUERY, loginEvent); if (loginEvent.Action == PlayerLoginAction.REJECT) { if ((slot.state & SlotState.DISCONNECTING) == 0) slot.Kick ("Disconnected by server."); return; } else if (loginEvent.Action == PlayerLoginAction.ASK_PASS) { slot.state = SlotState.PLAYER_AUTH; NetMessage.SendData (37, whoAmI, -1, ""); return; } // PlayerLoginAction.ACCEPT NetMessage.SendData (4, -1, whoAmI, player.Name, playerIndex); }
/// <summary> /// Hook method for player's initial connection to the server, before they can start playing /// </summary> /// <param name="Event">PlayerLoginEvent info</param> public virtual void onPlayerPreLogin(PlayerLoginEvent Event) { }
/// <summary> /// Hook method for player's initial connection to the server, before they can start playing /// </summary> /// <param name="Event">PlayerLoginEvent info</param> public virtual void onPlayerAuthReply(PlayerLoginEvent Event) { }
/// <summary> /// Hook method allowing to request the player to authenticate his name using a password /// </summary> /// <param name="Event">PlayerLoginEvent info</param> public virtual void onPlayerAuthQuery(PlayerLoginEvent Event) { }
public void Process(int start, int length, int num, int whoAmI, byte[] readBuffer, byte bufferData) { if (whoAmI == Main.myPlayer) { return; } var slot = Netplay.slots[whoAmI]; var player = Main.players[whoAmI]; bool firstTime = player.Name == null; int hairId = (int)readBuffer[start + 2]; if (hairId >= MAX_HAIR_ID) { hairId = 0; } player.whoAmi = whoAmI; player.hair = hairId; player.Male = readBuffer[start + 3] == 1; num += 3; num = setColor(player.hairColor, num, readBuffer); num = setColor(player.skinColor, num, readBuffer); num = setColor(player.eyeColor, num, readBuffer); num = setColor(player.shirtColor, num, readBuffer); num = setColor(player.underShirtColor, num, readBuffer); num = setColor(player.pantsColor, num, readBuffer); num = setColor(player.shoeColor, num, readBuffer); if (firstTime) player.Difficulty = readBuffer[num++]; string newName; try { newName = Encoding.ASCII.GetString(readBuffer, num, length - num + start).Trim(); } catch (ArgumentException) { slot.Kick ("Invalid name: contains non-ASCII characters."); return; } if (! firstTime) { if (player.Name != newName) { slot.Kick ("Attempt to change name during session."); } return; } player.Name = newName; if (player.Name.Length > 20) { slot.Kick ("Invalid name: longer than 20 characters."); return; } string address = slot.remoteAddress.Split(':')[0]; if (Program.server.BanList.containsException (address) || Program.server.BanList.containsException (player.Name)) { ProgramLog.Admin.Log ("Prevented user {0} from accessing the server.", newName); slot.Kick ("You are banned from this server."); return; } if (player.Name == "") { slot.Kick ("Invalid name: whitespace or empty."); return; } foreach (char c in player.Name) { if (c < 32 || c > 126) { slot.Kick ("Invalid name: contains non-printable characters."); return; } } if (player.Name.Contains (" " + " ")) { slot.Kick ("Invalid name: contains double spaces."); return; } Netplay.slots[whoAmI].oldName = player.Name; Netplay.slots[whoAmI].name = player.Name; var loginEvent = new PlayerLoginEvent(); loginEvent.Slot = slot; loginEvent.Sender = player; Program.server.PluginManager.processHook (Plugin.Hooks.PLAYER_AUTH_QUERY, loginEvent); if (loginEvent.Action == PlayerLoginAction.REJECT) { if ((slot.state & SlotState.DISCONNECTING) == 0) slot.Kick ("Rejected by server."); return; } else if (loginEvent.Action == PlayerLoginAction.ASK_PASS) { slot.state = SlotState.PLAYER_AUTH; NetMessage.SendData (37, whoAmI, -1, ""); return; } else // PlayerLoginAction.ACCEPT { // don't allow replacing connections for guests, but do for registered users if (slot.state < SlotState.PLAYING) { var name = player.Name.ToLower(); int count = 0; foreach (var otherPlayer in Main.players) { var otherSlot = Netplay.slots[otherPlayer.whoAmi]; if (count++ != whoAmI && otherPlayer.Name != null && name == otherPlayer.Name.ToLower() && otherSlot.state >= SlotState.CONNECTED) { slot.Kick ("A \"" + otherPlayer.Name + "\" is already on this server."); return; } } } NetMessage.SendData (4, -1, whoAmI, player.Name, whoAmI); } }
public override void onPlayerJoin(PlayerLoginEvent Event) { String msg = Event.Sender.Name + " has joined the server."; if (mircc.getIrcColors()) { msg = AIRCH.CODE_COLOR + "3" + msg; } mircc.sendToChan(msg); base.onPlayerJoin(Event); }
public override void onPlayerPreLogin(PlayerLoginEvent Event) { Event.setCancelled(false); }
public override void onPlayerJoin(PlayerLoginEvent Event) { int nPlayerIndex = Event.getPlayer().whoAmi; MyPlayer oPlayer = new MyPlayer(nPlayerIndex); Players[nPlayerIndex] = oPlayer; Event.setCancelled(false); }
public override void onPlayerJoin(PlayerLoginEvent Event) { //base.onPlayerKeyPress(Event); Player player = Event.Player; lastPos[player.whoAmi] = player.getLocation(); }
public override void onPlayerJoin(PlayerLoginEvent Event) { try { user = Event.Sender.Name.ToString().Replace(" ", "").ToLower(); FileStream primerread = new FileStream(pluginFolder + "/PlayerPerms/" + user + ".dat", FileMode.Open); BinaryReader binaryprimer = new BinaryReader(primerread); primer = binaryprimer.ReadInt32(); userperm = binaryprimer.ReadString(); binaryprimer.Close(); } catch { FileStream readStream = new FileStream(pluginFolder + "/AreaBank.dat", FileMode.Open); BinaryReader readBinary = new BinaryReader(readStream); spawnnumber = readBinary.ReadInt32(); userperm = readBinary.ReadString(); readStream.Close(); readBinary.Close(); primer = 1; FileStream primerwrite = new FileStream(pluginFolder + "/PlayerPerms/" + user + ".dat", FileMode.Create, FileAccess.ReadWrite); BinaryWriter primerwriter = new BinaryWriter(primerwrite); primerwriter.Write(primer); primerwriter.Write(userperm); primerwrite.Close(); } }
public static void OnPlayerJoined(int plr) { var msg = NetMessage.PrepareThreadInstance (); var motd = Program.properties.Greeting.Split('@'); for (int i = 0; i < motd.Length; i++) { if (motd[i] != null && motd[i].Trim().Length > 0) { msg.PlayerChat (255, motd[i], 0, 0, 255); } } string list = ""; for (int i = 0; i < 255; i++) { if (Main.players[i].Active) { if (list == "") list += Main.players[i].Name; else list = list + ", " + Main.players[i].Name; } } msg.PlayerChat (255, "Current players: " + list + ".", 255, 240, 20); msg.Send (plr); // send these before the login event, so messages from plugins come after var slot = Netplay.slots[plr]; var player = Main.players[plr]; PlayerLoginEvent loginEvent = new PlayerLoginEvent(); loginEvent.Slot = slot; loginEvent.Sender = player; Program.server.PluginManager.processHook(Plugin.Hooks.PLAYER_LOGIN, loginEvent); if ((loginEvent.Cancelled || loginEvent.Action == PlayerLoginAction.REJECT) && (slot.state & SlotState.DISCONNECTING) == 0) { slot.Kick ("Disconnected by server."); } else { slot.announced = true; // to player msg.Clear(); msg.SendSyncOthersForPlayer (plr); ProgramLog.Users.Log ("{0} @ {1}: ENTER {2}", slot.remoteAddress, plr, player.Name); if (player.HasHackedData()) { player.Kick("No Hacked Health or Mana is allowed."); } // to other players msg.Clear(); msg.PlayerChat (255, player.Name + " has joined.", 255, 240, 20); msg.ReceivingPlayerJoined (plr); msg.SendSyncPlayerForOthers (plr); // broadcasts the preceding message too } }
public static void GreetPlayer(int plr) { String[] motd = Program.properties.Greeting.Split('@'); for (int i = 0; i < motd.Length; i++) { if (motd != null && motd.Length > 0) { if (motd[i] != null && motd[i].Trim().Length > 0) { NetMessage.SendData(((int)Packet.PLAYER_CHAT), plr, -1, motd[i], 255, 0f, 0f, 255f); } } } String text = ""; for (int i = 0; i < 255; i++) { if (Main.players[i].Active) { if (text == "") { text += Main.players[i].Name; } else { text = text + ", " + Main.players[i].Name; } } } NetMessage.SendData(25, plr, -1, "Current players: " + text + ".", 255, 255f, 240f, 20f); PlayerLoginEvent loginEvent = new PlayerLoginEvent(); loginEvent.Slot = Netplay.slots[plr]; loginEvent.Sender = Main.players[plr]; Program.server.PluginManager.processHook(Plugin.Hooks.PLAYER_LOGIN, loginEvent); if ((loginEvent.Cancelled || loginEvent.Action == PlayerLoginAction.REJECT) && (loginEvent.Slot.state & SlotState.DISCONNECTING) == 0) Netplay.slots[plr].Kick ("Disconnected by server."); }
public override void onPlayerJoin(PlayerLoginEvent Event) { if ((coreMask & coreMaskArray[Event.Player.Difficulty]) == 0 && coreMask > 0) KickPlayer(Event.Player, "This server doesn't allow " + coreStrings[Event.Player.Difficulty] + " characters"); else if (onlyAllowNewPlayers) { int error; if (File.Exists(playersFolder + Path.DirectorySeparatorChar + Event.Player.Name + ".xml")) { error = LoadPlayerData(Event.Player); switch (error) { case PLAYER_NO_INVENTORY_MATCH: SetPlayerInvalid(Event.Player.Name); KickPlayer(Event.Player, differentInventoryMessage); break; case PLAYER_INVALID_MAXLIFE: if (checkMaxLife) { SetPlayerInvalid(Event.Player.Name); if (kickIfDifferentLifeMana) KickPlayer(Event.Player, maxLifeMessage); else Event.Player.sendMessage(maxLifeMessage, chatColor); } break; case PLAYER_INVALID_MAXMANA: if (checkMaxMana) { SetPlayerInvalid(Event.Player.Name); if (kickIfDifferentLifeMana) KickPlayer(Event.Player, maxManaMessage); else Event.Player.sendMessage(maxManaMessage, chatColor); } break; case PLAYER_VALID: SetPlayerValid(Event.Player); break; } } else { if (!PlayerHasNullInventory(Event.Player)) { if (kickIfHasInventory) KickPlayer(Event.Player, inventoryMessage); else { Event.Player.sendMessage(inventoryMessage, chatColor); SetPlayerInvalid(Event.Player.Name); } } else { GivePlayerStartingEquipment(Server.GetPlayerByName(Event.Player.Name)); SetPlayerValid(Event.Player, true); } } } // base.onPlayerJoin(Event); }
public static void syncPlayers() { bool flag = false; for (int i = 0; i < 255; i++) { int num = 0; if (Main.players[i].Active) { num = 1; } if (Netplay.serverSock[i].state == 10) { if (Main.autoShutdown && !flag) { string text = Netplay.serverSock[i].tcpClient.Client.RemoteEndPoint.ToString(); string a = text; for (int j = 0; j < text.Length; j++) { if (text.Substring(j, 1) == ":") { a = text.Substring(0, j); } } if (a == "127.0.0.1") { flag = true; } } NetMessage.SendData(14, -1, i, "", i, (float)num, 0f, 0f, 0); NetMessage.SendData(13, -1, i, "", i, 0f, 0f, 0f, 0); NetMessage.SendData(16, -1, i, "", i, 0f, 0f, 0f, 0); NetMessage.SendData(30, -1, i, "", i, 0f, 0f, 0f, 0); NetMessage.SendData(45, -1, i, "", i, 0f, 0f, 0f, 0); NetMessage.SendData(42, -1, i, "", i, 0f, 0f, 0f, 0); NetMessage.SendData(50, -1, i, "", i, 0f, 0f, 0f, 0); NetMessage.SendData(4, -1, i, Main.players[i].Name, i, 0f, 0f, 0f, 0); for (int k = 0; k < 44; k++) { NetMessage.SendData(5, -1, i, Main.players[i].inventory[k].Name, i, (float)k, 0f, 0f, 0); } NetMessage.SendData(5, -1, i, Main.players[i].armor[0].Name, i, 44f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[1].Name, i, 45f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[2].Name, i, 46f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[3].Name, i, 47f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[4].Name, i, 48f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[5].Name, i, 49f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[6].Name, i, 50f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[7].Name, i, 51f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[8].Name, i, 52f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[9].Name, i, 53f, 0f, 0f, 0); NetMessage.SendData(5, -1, i, Main.players[i].armor[10].Name, i, 54f, 0f, 0f, 0); if (!Netplay.serverSock[i].announced) { Netplay.serverSock[i].announced = true; NetMessage.SendData(25, -1, i, Main.players[i].Name + " has joined.", 255, 255f, 240f, 20f); if (Main.dedServ) { Program.tConsole.WriteLine(Main.players[i].Name + " has joined."); PlayerLoginEvent Event = new PlayerLoginEvent(); Event.Socket = Netplay.serverSock[i]; Event.Sender = Main.players[i]; Program.server.getPluginManager().processHook(Plugin.Hooks.PLAYER_LOGIN, Event); } } } else { NetMessage.SendData(14, -1, i, "", i, (float)num, 0f, 0f); if (Netplay.serverSock[i].announced) { Netplay.serverSock[i].announced = false; NetMessage.SendData(25, -1, i, Netplay.serverSock[i].oldName + " has left.", 255, 255f, 240f, 20f); if (Main.dedServ) { Program.tConsole.WriteLine(Netplay.serverSock[i].oldName + " has left."); PlayerLogoutEvent Event = new PlayerLogoutEvent(); Event.Socket = Netplay.serverSock[i]; Event.Sender = Main.players[i]; Program.server.getPluginManager().processHook(Plugin.Hooks.PLAYER_LOGOUT, Event); } } } } if (Main.autoShutdown && !flag) { Commands.Commands.SaveAll(); Netplay.disconnect = true; } }