forked from facebookarchive/RakNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMasterServerMain.cpp
More file actions
129 lines (115 loc) · 3.24 KB
/
Copy pathMasterServerMain.cpp
File metadata and controls
129 lines (115 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
// This is my own internal test program for the master server but serves as a good example.
#include "MasterCommon.h"
#include "MasterServer.h"
#include "RakNetworkFactory.h"
#include "RakPeerInterface.h"
#include <cstdio>
#include <cstring>
#ifdef WIN32
#include <conio.h>
#else
#include "../Unix/kbhit.h"
#endif
#ifdef _WIN32
#include <conio.h>
#include <windows.h> // Sleep
#else
#include "../Unix/kbhit.h"
#include <unistd.h> // usleep
#endif
#define READCHAR(arg) gets(arg); ch=arg[0];
int main(void)
{
MasterServer masterServer;
int serverListSize;
const char *outputString;
int outputInt;
bool identiferFound;
int index;
char ch;
Packet *p;
RakPeerInterface *testGameMasterServer;
testGameMasterServer = RakNetworkFactory::GetRakPeerInterface();
testGameMasterServer->Initialize(10, 60000, 0);
testGameMasterServer->SetMaximumIncomingConnections(8);
testGameMasterServer->AttachPlugin(&masterServer);
printf("This project shows how to use the master server.\n");
printf("The master server is a plugin that maintains a list of games uplodated.\n");
printf("by the master client.\n");
printf("Difficulty: Beginner\n\n");
printf("(p)rint\n(q)uit\n");
char buff[256];
while (1)
{
if (kbhit())
{
READCHAR(buff);
if (ch=='q')
break;
else if (ch=='p')
{
serverListSize=masterServer.GetServerListSize();
if (serverListSize==0)
{
printf("No servers in list\n");
}
else
{
for (index=0; index < serverListSize; index++)
{
printf("%i. ", index);
outputString=masterServer.GetServerListRuleAsString(index, "IP", &identiferFound);
if (identiferFound)
printf("%s:", outputString);
else
printf("NO_IP:");
outputInt=masterServer.GetServerListRuleAsInt(index, "Port", &identiferFound);
if (identiferFound)
printf("%i ", outputInt);
else
printf("NO_PORT ");
outputString=masterServer.GetServerListRuleAsString(index, "Game type", &identiferFound);
if (identiferFound)
printf("%s ", outputString);
else
printf("NIL_GT ");
outputString=masterServer.GetServerListRuleAsString(index, "Game name", &identiferFound);
if (identiferFound)
printf("%s ", outputString);
else
printf("NIL_GN ");
outputInt=masterServer.GetServerListRuleAsInt(index, "Score", &identiferFound);
if (identiferFound)
printf("%i\n", outputInt);
else
printf("NO_SCORE\n");
}
}
}
ch=0;
}
p = testGameMasterServer->Receive();
while (p)
{
// Ignore any game packets. The master server plugin handles everything.
testGameMasterServer->DeallocatePacket(p);
// Call Receive every update to keep the plugin going
p = testGameMasterServer->Receive();
}
#ifdef _WIN32
Sleep(30);
#else
usleep(30 * 1000);
#endif
}
return 0;
}