-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.cpp
124 lines (89 loc) · 2.7 KB
/
session.cpp
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
/*
SESSION.CPP v0.15
Game creation/join
Copyright (c) 2004 Francesco Orsenigo <francesco.orsenigo@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <unistd.h>
#include "main.h"
#include "game.h"
#include "net.h"
#include "boxgui.h"
#include "cmd.h"
/*=============================================================================
* JOIN
* Join a game.
*/
int sessionJoin(char* join)
{
char* address = join? join : (char*)"localhost";
// shut current game and network
void mainCloseAll();
mainCloseAll();
// connect to server
// calls gameSetSelf() too
if(netConnect(address) == -1)
{
// if we're hosting a game, (ie, 'join' is 0) and the spawn failed,
// it's better to inform the user.
if(!join)
{
pe("Could not spawn server. Check that:\n");
pe(" 1. all game files are correct. Try running 'everborn dedicated' and see the errors.\n");
pe(" 2. no other everborn servers are running. Try 'killall -9 everborn'.\n");
}
return -1;
}
if(net_connections->requests)
chclSendRequest(net_connections, net_connections->requests);
// enter init menu
bOpen("multi");
return 0;
}
static int cmd_join() { sessionJoin(arg1.s); }
static cmdC cmdJoin(
"join", // name
"N: address", // syntax
"join a game",
cmd_join, // exec()
NULL,
NULL
);
/*=============================================================================
* HOST
* Creates a new game.
*/
int sessionHost(char* game_str)
{
// the game string contains all the paramters for a new game
void serverSetGameString(char*);
serverSetGameString(game_str);
// spawn server
pf("spawning server...\n");
scrsndClose();
if(!fork()) // child is server
serverMainLoop(); // serverMainLoop() never returns
scrsndInit();
// from now on, you are a client with nothing special!
return sessionJoin(0);
}
static int cmd_host() { sessionHost(arg1.s); }
static cmdC cmdHost(
"host", // name
"S: game string", // syntax
"create a new game",
cmd_host, // exec()
NULL,
NULL
);
//EOF =========================================================================