Cube  Diff

Differences From Artifact [6542299bf2]:

To Artifact [d14310e680]:


1
2
3
4

5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
12




+







// client.cpp, mostly network related client game code

#include "cube.h"

#import "Command.h"
#import "DynamicEntity.h"

static ENetHost *clienthost = NULL;
static int connecting = 0;
static int connattempts = 0;
static int disconnecting = 0;
// our client id in the game
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
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







-
+









+
-
+
+
+

-
+









+
-
+
+
+







	if (!clienthost || connecting)
		return;
	assert(ENET_PEER_PACKET_THROTTLE_SCALE == 32);
	enet_peer_throttle_configure(clienthost->peers,
	    throttle_interval * 1000, throttle_accel, throttle_decel);
}

void
static void
newname(OFString *name)
{
	c2sinit = false;

	if (name.length > 16)
		name = [name substringToIndex:16];

	player1.name = name;
}

COMMANDN(name, newname, ARG_1STR)
COMMAND(name, ARG_1STR, ^(OFString *name) {
	newname(name);
})

void
static void
newteam(OFString *name)
{
	c2sinit = false;

	if (name.length > 5)
		name = [name substringToIndex:5];

	player1.team = name;
}

COMMANDN(team, newteam, ARG_1STR)
COMMAND(team, ARG_1STR, ^(OFString *name) {
	newteam(name);
})

void
writeclientinfo(OFStream *stream)
{
	[stream writeFormat:@"name \"%@\"\nteam \"%@\"\n", player1.name,
	        player1.team];
}
173
174
175
176
177
178
179
180
181

182
183
184
185


186
187
188
189








190
191
192
193
194
195
196
180
181
182
183
184
185
186


187

188


189
190




191
192
193
194
195
196
197
198
199
200
201
202
203
204
205







-
-
+
-

-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+







void
toserver(OFString *text)
{
	conoutf(@"%@:\f %@", player1.name, text);
	ctext = text;
}

void
echo(OFString *text)
COMMAND(echo, ARG_VARI, ^(OFString *text) {
{
	conoutf(@"%@", text);
}

})
COMMAND(say, ARG_VARI, ^(OFString *text) {
COMMAND(echo, ARG_VARI)
COMMANDN(say, toserver, ARG_VARI)
COMMANDN(connect, connects, ARG_1STR)
COMMANDN(disconnect, trydisconnect, ARG_NONE)
	toserver(text);
})
COMMAND(connect, ARG_1STR, ^(OFString *servername) {
	connects(servername);
})
COMMAND(disconnect, ARG_NONE, ^{
	trydisconnect();
})

// collect c2s messages conveniently

static OFMutableArray<OFData *> *messages;

void
addmsg(int rel, int num, int type, ...)
235
236
237
238
239
240
241
242
243

244
245
246

247
248
249
250
251
252
253
254
244
245
246
247
248
249
250


251

252

253

254
255
256
257
258
259
260







-
-
+
-

-
+
-








int lastupdate = 0, lastping = 0;
OFString *toservermap;
bool senditemstoserver =
    false; // after a map change, since server doesn't have map data

OFString *clientpassword;
void
password(OFString *p)
COMMAND(password, ARG_1STR, ^(OFString *p) {
{
	clientpassword = p;
}
})
COMMAND(password, ARG_1STR)

bool
netmapstart()
{
	senditemstoserver = true;
	return clienthost != NULL;
}