Skip to content

Output a notification to the console when a player is connected and disconnected

s2s-k edited this page Aug 13, 2022 · 2 revisions

The code below will show you an example of how to handle players connecting and disconnecting from the server.

#include <iostream>

import TrilogyOnline.SDK.Fundamental;
import TrilogyOnline.SDK.Game;
import TrilogyOnline.SDK.Version;
import TrilogyOnline.SDK.Player;

using namespace TrilogyOnline;
using namespace TrilogyOnline::API;

class CGameState : public CGame::CState
{
public:
	void OnTick(CGame& game) override
	{

	}

	void OnPlayerConnected(CGame& game, CPlayer& player) override
	{
		std::cout << "Player connected!" << std::endl;
	}

	void OnPlayerDisconnected(CGame& game, CPlayer& player) override
	{
		std::cout << "Player disconnected..." << std::endl;
	}
};

CGameState GameState;

void Startup(API::CGame& game)
{
	game.ServerStartup(u"product key");

	game.SetState(&GameState);
}

void Shutdown(API::CGame& game)
{
	game.SetState(nullptr);

	game.ServerShutdown();
}

UInt32 GetSDKVersion()
{
	return API::Version;
}