Cube  Diff

Differences From Artifact [72369d5670]:

To Artifact [f8f6147037]:


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
		return;
	assert(ENET_PEER_PACKET_THROTTLE_SCALE == 32);
	enet_peer_throttle_configure(clienthost->peers,
	    throttle_interval * 1000, throttle_accel, throttle_decel);
}

void
newname(char *name)
{
	c2sinit = false;

	strn0cpy(player1->name, name, 16);
}



void
newteam(char *name)
{
	c2sinit = false;

	strn0cpy(player1->team, name, 5);
}

COMMANDN(team, newteam, ARG_1CSTR)
COMMANDN(name, newname, ARG_1CSTR)

void
writeclientinfo(FILE *f)
{
	fprintf(f, "name \"%s\"\nteam \"%s\"\n", player1->name, player1->team);
}

void
connects(char *servername)
{

	disconnect(1); // reset state
	addserver(servername);

	conoutf(@"attempting to connect to %s", servername);
	ENetAddress address = {ENET_HOST_ANY, CUBE_SERVER_PORT};
	if (enet_address_set_host(&address, servername) < 0) {

		conoutf(@"could not resolve server %s", servername);
		return;
	};


	clienthost = enet_host_create(NULL, 1, rate, rate);

	if (clienthost) {
		enet_host_connect(clienthost, &address, 1);
		enet_host_flush(clienthost);
		connecting = lastmillis;
		connattempts = 0;
	} else {
		conoutf(@"could not connect to server");
		disconnect();

	}
}

void
disconnect(int onlyclean, int async)
{
	if (clienthost) {







|


>
|
|
|
>
>

|


>
|
|
|
|
<








|

>
|
|

|
|
|
>
|
|
<
|
>
|

|
|
|
|
|
|
|
|
>







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
		return;
	assert(ENET_PEER_PACKET_THROTTLE_SCALE == 32);
	enet_peer_throttle_configure(clienthost->peers,
	    throttle_interval * 1000, throttle_accel, throttle_decel);
}

void
newname(OFString *name)
{
	c2sinit = false;
	@autoreleasepool {
		strn0cpy(player1->name, name.UTF8String, 16);
	}
}
COMMANDN(name, newname, ARG_1STR)

void
newteam(OFString *name)
{
	c2sinit = false;
	@autoreleasepool {
		strn0cpy(player1->team, name.UTF8String, 5);
	}
}
COMMANDN(team, newteam, ARG_1STR)


void
writeclientinfo(FILE *f)
{
	fprintf(f, "name \"%s\"\nteam \"%s\"\n", player1->name, player1->team);
}

void
connects(OFString *servername)
{
	@autoreleasepool {
		disconnect(1); // reset state
		addserver(servername);

		conoutf(@"attempting to connect to %s", servername.UTF8String);
		ENetAddress address = {ENET_HOST_ANY, CUBE_SERVER_PORT};
		if (enet_address_set_host(&address, servername.UTF8String) <
		    0) {
			conoutf(@"could not resolve server %s", servername);
			return;

		}

		clienthost = enet_host_create(NULL, 1, rate, rate);

		if (clienthost) {
			enet_host_connect(clienthost, &address, 1);
			enet_host_flush(clienthost);
			connecting = lastmillis;
			connattempts = 0;
		} else {
			conoutf(@"could not connect to server");
			disconnect();
		}
	}
}

void
disconnect(int onlyclean, int async)
{
	if (clienthost) {
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
echo(char *text)
{
	conoutf(@"%s", text);
}

COMMAND(echo, ARG_VARI)
COMMANDN(say, toserver, ARG_VARI)
COMMANDN(connect, connects, ARG_1CSTR)
COMMANDN(disconnect, trydisconnect, ARG_NONE)

// collect c2s messages conveniently

vector<ivector> messages;

void







|







175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
echo(char *text)
{
	conoutf(@"%s", text);
}

COMMAND(echo, ARG_VARI)
COMMANDN(say, toserver, ARG_VARI)
COMMANDN(connect, connects, ARG_1STR)
COMMANDN(disconnect, trydisconnect, ARG_NONE)

// collect c2s messages conveniently

vector<ivector> messages;

void
214
215
216
217
218
219
220
221
222

223
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
int lastupdate = 0, lastping = 0;
OFString *toservermap;
bool senditemstoserver =
    false; // after a map change, since server doesn't have map data

string clientpassword;
void
password(char *p)
{

	strcpy_s(clientpassword, p);
}

COMMAND(password, ARG_1CSTR)

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

void
initclientnet()
{
	ctext[0] = 0;
	toservermap = @"";
	clientpassword[0] = 0;
	newname("unnamed");
	newteam("red");
}

void
sendpackettoserv(void *packet)
{
	if (clienthost) {
		enet_host_broadcast(clienthost, 0, (ENetPacket *)packet);







|

>
|
|
>
|














|
|







220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
int lastupdate = 0, lastping = 0;
OFString *toservermap;
bool senditemstoserver =
    false; // after a map change, since server doesn't have map data

string clientpassword;
void
password(OFString *p)
{
	@autoreleasepool {
		strcpy_s(clientpassword, p.UTF8String);
	}
}
COMMAND(password, ARG_1STR)

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

void
initclientnet()
{
	ctext[0] = 0;
	toservermap = @"";
	clientpassword[0] = 0;
	newname(@"unnamed");
	newteam(@"red");
}

void
sendpackettoserv(void *packet)
{
	if (clienthost) {
		enet_host_broadcast(clienthost, 0, (ENetPacket *)packet);