Skip to content

AI generated "Official API" documentation

Rain edited this page Aug 7, 2024 · 5 revisions

WARNING! This has been generated using ChatGPT.

Overview

The GameServer class manages the server-side logic for a game, handling player connections, server settings, and communication between clients and the server. This class includes various properties, methods, and event handlers to maintain the server's state and interact with connected players.

Namespace

Public Properties

Server Properties

ulong ServerHash: Unique hash for the server.
bool IsConnected: Indicates if the server is currently connected.
IPAddress GameIP: IP address of the game server.
int GamePort: Port number on which the game server is running.
bool IsPasswordProtected: Indicates if the server is password protected.
string ServerName: Name of the server.
string Gamemode: Current game mode.
string Map: Current map.
MapSize MapSize: Size of the map.
MapDayNight DayNight: Day/night cycle status.
int CurrentPlayerCount: Number of currently connected players.
int InQueuePlayerCount: Number of players in the queue.
int MaxPlayerCount: Maximum number of players allowed on the server.
uint RoundIndex: Index of the current round.
long SessionID: Session ID.
ServerSettings ServerSettings: Server settings.
MapRotation MapRotation: Map rotation settings.
GamemodeRotation GamemodeRotation: Game mode rotation settings.
RoundSettings RoundSettings: Round settings.
string TerminationReason: Reason for server termination.
bool ReconnectFlag: Indicates if a reconnect is required.
string LoadingScreenText: Text displayed on the loading screen.
string ServerRulesText: Text displayed for server rules.
Player and Squad Properties
IEnumerable<Squad> TeamASquads: Collection of squads for Team A.
IEnumerable<Squad> TeamBSquads: Collection of squads for Team B.
IEnumerable<Squad> AllSquads: Collection of all squads.

Public Methods

Server Control Methods

void WriteToSocket(Common.Serialization.Stream pck): Writes a packet to the server socket.
void ExecuteCommand(string cmd): Executes a command on the server.
void SetNewPassword(string newPassword): Sets a new password for the server.
void SetPingLimit(int newPing): Sets the maximum allowed ping for players.
void AnnounceShort(string msg): Sends a short announcement to all players.
void AnnounceLong(string msg): Sends a long announcement to all players.
void UILogOnServer(string msg, float messageLifetime): Logs a message on the server UI.
void ForceStartGame(): Forces the game to start.
void SetServerSizeForNextMatch(MapSize size): Sets the server size for the next match.
void ForceEndGame(): Forces the game to end.
void ForceEndGame(Team team): Forces the game to end for a specific team.
void ForceEndGame(List<EndGamePlayer> players): Forces the game to end with specified player scores.
void SayToAllChat(string msg): Sends a message to all players in chat.
void SayToChat(string msg, ulong steamID): Sends a message to a specific player.
void SayToChat(string msg, Player player): Sends a message to a specific player.
void SetLoadingScreenText(string newText): Sets the loading screen text.
void SetRulesScreenText(string newText): Sets the rules screen text.
void StopServer(): Stops the server.
void CloseServer(): Closes the server.
void KickAllPlayers(): Kicks all players from the server.
void Kick(ulong steamID, string reason): Kicks a specific player.
void Kick(Player player, string reason): Kicks a specific player.
void Kill(ulong steamID): Kills a specific player.
void Kill(Player player): Kills a specific player.
void ChangeTeam(ulong steamID): Changes the team of a specific player.
void ChangeTeam(Player player): Changes the team of a specific player.
void ChangeTeam(ulong steamID, Team team): Changes the team of a specific player to a specified team.
void ChangeTeam(Player player, Team team): Changes the team of a specific player to a specified team.
void KickFromSquad(ulong steamID): Kicks a player from their squad.
void KickFromSquad(Player player): Kicks a player from their squad.
void JoinSquad(ulong steamID, Squads targetSquad): Makes a player join a specified squad.
void JoinSquad(Player player, Squads targetSquad): Makes a player join a specified squad.
void DisbandPlayerSquad(ulong steamID): Disbands a player's squad.
void DisbandPlayerCurrentSquad(Player player): Disbands a player's current squad.
void PromoteSquadLeader(ulong steamID): Promotes a player to squad leader.
void PromoteSquadLeader(Player player): Promotes a player to squad leader.
void Teleport(ulong steamID, Vector3 position): Teleports a player to a specified position.
void Teleport(Player player, Vector3 position): Teleports a player to a specified position.
void WarnPlayer(ulong steamID, string msg): Sends a warning message to a player.
void WarnPlayer(Player player, string msg): Sends a warning message to a player.
void MessageToPlayer(ulong steamID, string msg): Sends a message to a player.
void MessageToPlayer(Player player, string msg): Sends a message to a player.
void MessageToPlayer(ulong steamID, string msg, float fadeOutTime): Sends a message to a player with a fade-out time.
void MessageToPlayer(Player player, string msg, float fadeOutTime): Sends a message to a player with a fade-out time.
void SetRoleTo(ulong steamID, GameRole role): Sets the role of a player.
void SetRoleTo(Player player, GameRole role): Sets the role of a player.
void SpawnPlayer(ulong steamID, PlayerLoadout loadout, PlayerWearings wearings, Vector3 position, Vector3 lookDirection, PlayerStand stand, float spawnProtection): Spawns a player with specified settings.
void SpawnPlayer(Player player, PlayerLoadout loadout, PlayerWearings wearings, Vector3 position, Vector3 lookDirection, PlayerStand stand, float spawnProtection): Spawns a player with specified settings.
void SetHP(ulong steamID, float newHP): Sets the health points of a player.
void SetHP(Player player, float newHP): Sets the health points of a player.
void GiveDamage(ulong steamID, float damage): Deals damage to a player.
void GiveDamage(Player player, float damage): Deals damage to a player.
void Heal(ulong steamID, float heal): Heals a player.
void Heal(Player player, float heal): Heals a player.
void SetSquadPointsOf(Team team, Squads squad, int points): Sets the points of a squad.
void SetPrimaryWeapon(ulong steamID, WeaponItem item, int extraMagazines, bool clear = false): Sets the primary weapon of a player.
void SetPrimaryWeapon(Player player, WeaponItem item, int extraMagazines, bool clear = false): Sets the primary weapon of a player.
void SetSecondaryWeapon(ulong steamID, WeaponItem item, int extraMagazines, bool clear = false): Sets the secondary weapon of a player.
void SetSecondaryWeapon(Player player, WeaponItem item, int extraMagazines, bool clear = false): Sets the secondary weapon of a player.
void SetFirstAid(ulong steamID, string tool, int extra, bool clear = false): Sets the first aid tool of a player.
void SetFirstAid(Player player, string tool, int extra, bool clear = false): Sets the first aid tool of a player.
void SetLightGadget(ulong steamID, string tool, int extra, bool clear = false): Sets the light gadget of a player.
void SetLightGadget(Player player, string tool, int extra, bool clear = false): Sets the light gadget of a player.
void SetHeavyGadget(ulong steamID, string tool, int extra, bool clear = false): Sets the heavy gadget of a player.
void SetHeavyGadget(Player player, string tool, int extra, bool clear = false): Sets the heavy gadget of a player.
void SetThrowable(ulong steamID, string tool, int extra, bool clear = false): Sets the throwable of a player.
void SetThrowable(Player player, string tool, int extra, bool clear = false): Sets the throwable of a player.
void PlaceVoxelBlock(Vector3 position, VoxelBlockData data): Places a voxel block at a specified position.
void DestroyVoxelBlock(Vector3 position): Destroys a voxel block at a specified position.

Player Enumeration Methods

IEnumerable AllPlayers: Enumerates all players.
IEnumerable AllTeamAPlayers: Enumerates all players in Team A.
IEnumerable AllTeamBPlayers: Enumerates all players in Team B.
IEnumerable PlayersOf(Team team): Enumerates players of a specified team.
IEnumerable SearchPlayerByName(string keyword): Searches players by name.
IEnumerable SearchPlayerByName(params string[] keywords): Searches players by multiple keywords.
bool TryGetPlayer(ulong steamID, out TPlayer player): Attempts to get a player by Steam ID.

Event Handling Methods

virtual async Task OnConnected(): Invoked when the server is connected.
virtual async Task OnTick(): Invoked on each server tick.
virtual async Task OnDisconnected(): Invoked when the server is disconnected.
virtual async Task OnPlayerConnected(TPlayer player): Invoked when a player connects.
virtual async Task OnPlayerDisconnected(TPlayer player): Invoked when a player disconnects.
virtual async Task OnPlayerTypedMessage(TPlayer player, ChatChannel channel, string msg): Invoked when a player sends a message.
virtual async Task OnPlayerJoiningToServer(ulong steamID, PlayerJoiningArguments args): Invoked when a player is joining the server.
virtual async Task OnSavePlayerStats(ulong steamID, PlayerStats stats): Invoked to save player stats.
virtual async Task OnPlayerRequestingToChangeRole(TPlayer player, GameRole requestedRole): Invoked when a player requests to change role.
virtual async Task OnPlayerRequestingToChangeTeam(TPlayer player, Team requestedTeam): Invoked when a player requests to change team.
virtual async Task OnPlayerChangedRole(TPlayer player, GameRole role): Invoked when a player changes role.
virtual async Task OnPlayerJoinedSquad(TPlayer player, Squad squad): Invoked when a player joins a squad.
virtual async Task OnSquadLeaderChanged(Squad squad, TPlayer newLeader): Invoked when a squad leader changes.
virtual async Task OnPlayerLeftSquad(TPlayer player, Squad squad): Invoked when a player leaves a squad.
virtual async Task OnPlayerChangeTeam(TPlayer player, Team team): Invoked when a player changes team.
virtual async Task OnSquadPointsChanged(Squad squad, int newPoints): Invoked when squad points change.
virtual async Task<OnPlayerSpawnArguments?> OnPlayerSpawning(TPlayer player, OnPlayerSpawnArguments request): Invoked when a player is spawning.
virtual async Task OnPlayerSpawned(TPlayer player): Invoked when a player has spawned.
virtual async Task OnPlayerDied(TPlayer player): Invoked when a player dies.
virtual async Task OnPlayerGivenUp(TPlayer player): Invoked when a player gives up.
virtual async Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments args): Invoked when a player downs another player.
virtual async Task OnAPlayerRevivedAnotherPlayer(TPlayer from, TPlayer to): Invoked when a player revives another player.
virtual async Task OnPlayerReported(TPlayer from, TPlayer to, ReportReason reason, string additional): Invoked when a player reports another player.
virtual async Task OnGameStateChanged(GameState oldState, GameState newState): Invoked when the game state changes.
virtual async Task OnRoundStarted(): Invoked when a round starts.
virtual async Task OnRoundEnded(): Invoked when a round ends.
virtual async Task OnSessionChanged(long oldSessionID, long newSessionID): Invoked when the session changes.

Squad Methods

IEnumerable IterateMembersOf(Squad squad): Enumerates members of a squad.
Squad GetSquad(Team team, Squads name): Gets a squad by team and name.

Connection and Disposal Methods

void CloseConnection(string additionInfo = ""): Closes the connection with additional information.
void Dispose(): Disposes the server resources.
override string ToString(): Returns a string representation of the server.

This documentation provides a detailed overview of the GameServer class, its properties, methods, and internal workings. This should help in understanding and utilizing the class effectively in your .NET 6 application.