Vietcong server API

Compatible with .NET Framework 4.8

Player methods
Player properties
VcdedAPI Public API
Events
  • OnChatMessage
    Event triggered when a player sends a chat message.
    What you get:
    • Player player – the player who sent the message (null for system messages)
    • string content – the message text
  • OnPlayerConnection
    Event triggered when a player joins the server.
    What you get:
    • Player player – the player who connected
  • OnPlayerRecover
    Event triggered when a player respawns or recovers in the game.
    What you get:
    • Player player – the player who respawned or recovered
  • OnClientConnection
    Event triggered when a client connects to the server.
    What you get:
    • string ipAddress – IP address of the client
    • int id – player ID if known
    • int clientId – client ID if known
  • OnPlayerWeaponChange
    Event triggered when a player changes their weapon.
    What you get:
    • Player player – the player who changed weapon
    • int oldWeapon – previous weapon ID
    • int newWeapon – new weapon ID
  • OnPlayerMove
    Event triggered when a player moves in the game world.
    What you get:
    • Player player – the player who moved
    • Vector3 newPosition – new position coordinates
  • OnWeaponBayonet
    Event triggered when a player equips or unequips a bayonet.
    What you get:
    • Player player – the player who changed bayonet state
    • bool hasBayonet – true if equipped, false if removed
Methods
  • VcdedAPI(string host, int port, bool allowOverInternet)
    Constructor. Initializes the API and starts monitoring threads for chat, players, and connections.
  • GetPlayers() : List<Player>
    Returns a list of online players (Ping > 0).
  • GetEnemies() : List<Player>
    Returns a list of enemy players (Ping == 0).
  • GetEntities() : List<Player>
    Returns a list of all player entities.
  • GetPlayersCount() : int
    Returns the count of currently online players.
  • GetMaplist() : List<MapEntry>
    Retrieves the full map list from the server.
  • GetCurrentMap() : MapEntry
    Returns the currently active map.
  • SwitchMap(MapEntry map = null)
    Switches to the specified map; if null, goes to the next map in the list.
  • SwitchMap(int index)
    Switches to a map by index; -1 moves to the next map.
  • EnableFriendlyFire(bool enabled)
    Enables or disables friendly fire on the server.
  • EnableVietnamMode(bool enabled)
    Hides HUD, ammo, and magazines for a "Vietnam mode".
  • EnableVietnamModeChat(bool enabled)
    Enables or disables Vietnam mode style chat.
  • EnableBlackDeathScreen(bool enabled)
    Enables a black screen effect when the player dies.
  • SetServerPassword(string password = null)
    Sets the server password; null disables it.
  • SetAdminPassword(string password = null)
    Sets the admin password; null disables it.
  • SetSpectators(int count, int delay)
    Sets the number of spectators and the view delay.
  • Say(string message)
    Sends a message as administrator to all players (Host on DC).
  • AdminSay(string message)
    Sends a message as administrator visible only to other admins.
  • CreateExplosion(Vector3 position, ExplosionType explosionType)
    Creates a specified explosion type at the given position.
  • SpawnItem(Vector3 position, Item item)
    Spawns a specified item at a given position.
  • SpawnItemWithDirection(Vector3 position, Vector3 direction, Item item)
    Spawns an item at a position with a direction vector.
  • IgnoreMessagesStartsWith(char symbol)
    Ignores chat messages starting with a specified symbol.
  • static ExecRaw(string command, bool recursive = false)
    Executes a raw server command.
  • CrashServer() : bool
    Attempts to crash the server (used for testing). Returns true if successful.
  • SendMessage(MessageType messageType, int id, string content)
    Sends a message to a player or server with a specific message type.
Installation & Use
  1. Unzip vcded.exe and vcded.dll file to the Vietcong server directory and replace them.
  2. Run the server as normal using the new vcded.exe
  3. Now open Visual Studio or whatever IDE you use and create a new C# project.
  4. Link the DLL vcdedconnector.dll to the C# project and you can use the API.
  5. Use directivity using vcdedconnector;

Here you have some example code you can use:

string hostAddress = "127.0.0.1";
int port = 2000;

VcdedAPI api = new VcdedAPI(hostAddress, port, false);

api.OnChatMessage += (sender, e) =>
{
    if (e.Message.Equals("/swap"))
    {
        e.Player?.Swap();
    }
    else if (e.Message.Equals("/ping"))
    {
        e.Player?.SendMessage(MessageType.HostOnDC, "PONG! Aprox: " + e.Player.Ping);
    }
    else if (e.Message.Equals("/ip"))
    {
        e.Player?.SendMessage(MessageType.HostOnDC, "Your IP: " + e.Player.Ip);
    }
};

api.OnPlayerConnection += (sender, e) =>
{
    // waits until player choose side and the gun
    e?.BlockThreadUntilSpawned();

    e.Player?.SendMessage(MessageType.HostOnDC, "Welcome on the server " + e.Player.Name + "!");
};

api.OnClientConnection += (sender, e) =>
{
    // waits until client (player) fully establish connection and receives the full handshake
    e?.WaitUntilClientEstablishFullConnection();

    api.SendMessage(MessageType.Console, e.Id, "You are joining to our server! Welcome!");
};