-
Notifications
You must be signed in to change notification settings - Fork 1
ModesServer
There are two modes of operation for the Snipe server. The normal mode of operation is when each slave server (that consists of a metaserver with multiple main threads) and cache server are ran as separate applications. You will need to compile separate Neko files for all of these. You can run these applications on different physical machines thus increasing the amount of resources available to the game. All of the server to server communication is done through TCP/IP connections and will be slower than thread messaging since each message needs to be serialized/deserialized and possibly compressed/decompressed.
Compiling the server application in the uniserver mode produces a single Neko file. In this mode cache server and slave servers are all running in the same application as separate threads. All communication between servers is through the thread messaging of links to anonymous objects. Since no serialization needs to happen and it's done thread to thread, the communication is very fast. It's also more convenient to start and stop the uniserver application. The drawback, of course, is that the server application is limited by the resources of a single physical machine.
Note that you will not need to add any additional code to switch between modes of operation. You can find the examples in the following sections in core/examples/testProject/
folder.
The normal mode will require separate Neko files for each type of slave server plus one for cache server.
Example cacheserver.hxml
(don't forget to fix class paths for your project):
-main CacheServerTest
-neko cacheserver.n
-cp ../game/
-cp ../../../
-cp ../../../tools/threadname/
-cp ../../../external-libs/npostgres/
Example CacheServerTest
:
import snipe.cache.CacheServer;
import snipe.cache.SlaveClient;
class CacheServerTest extends CacheServer
{
function new()
{
super();
}
public override function initModules()
{
loadModules([]);
slaveClientClass = TestGameServer;
}
static var s: CacheServerTest;
static function main()
{
s = new CacheServerTest();
s.initServer();
s.start();
}
}
The main()
method in this case is straightforward, all details of initialization are in the initModules()
:
loadModules([]);
This call loads any project-specific cache server modules.
slaveClientClass = TestGameServer;
This sets up the slave client class.
Example hserver.hxml
to build test game server:
-main ServerTest
-neko hserver.n
-cp ../../../
-cp ../../../tools/threadname/
Example ServerTest
:
import snipe.slave.MetaServer;
import snipe.slave.Server;
import snipe.slave.ServerGame;
import snipe.slave.ClientInfo;
class ServerTest extends ServerGame
{
function new(metav: MetaServer, idv: Int)
{
super(metav, idv);
}
override function initModulesGame()
{
loadModules([ modules.TestModule ]);
addNoLoginRequests([ 'test.test', 'test.test2',
'test.cacheget', 'test.cacheupdate', 'test.cacheupdate2',
'test.cacheupdatefixed', 'test.cacheupdateparams' ]);
}
static var s: ServerTest;
static function main()
{
var meta = new MetaServer('game', ServerTest, TestClient);
meta.initServer();
meta.start();
}
}
Making the uniserver will require the compilation of the class that extends UniServer
class and defining the -D uniserver
compiler parameter.
Example uniserver.hxml
file (you will have to fix class paths for your project):
-main UniServerTest
-neko uniserver.n
-dce no
-D uniserver
-D no-pattern-matching
-D deprecation-warnings
-cp ../../core/
-cp ../../core/tools/threadname/
-cp ../../core/external-libs/npostgres/
-cp ../common/
-cp ../cache/
-cp ../game/
-cp ../chat/
Example UniServerTest
class that extends UniServer
and initializes everything:
import snipe.cache.UniServer;
class UniServerTest extends UniServer
{
function new()
{
super();
}
// main function
static var u: UniServerTest;
static function main()
{
u = new UniServerTest();
u.cacheClass = CacheServerTest;
u.slaveInfos = [
{
type: 'game',
client: TestClient,
server: ServerTest,
},
];
u.init();
u.start();
}
}
The main()
method of the class will have to supply all of the server classes. Here is a line by line guide for it with explanations.
u = new UniServerTest();
Creates a uniserver class instance.
u.cacheClass = CacheServerTest;
Sets the cache server class. The minimal class is provided above in the normal mode section.
u.slaveInfos = [
{
type: 'game',
client: Client,
server: ServerTest,
},
];
This sets the data required to run slave servers. The data is the type name, client and server classes. In this example one metaserver will be created - game server. The minimal classes for clients and slave servers are provided in the normal mode section above.
u.init();
Initializes internal server state.
u.start();
Starts the uniserver.