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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
206
207
208
209
210
211
212
213
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
--- cmn/role.cpp.orig 2012-05-27 06:52:30.000000000 +0900
+++ cmn/role.cpp 2012-05-27 06:53:11.000000000 +0900
@@ -29,9 +29,9 @@
#include "stdafx.h"
-#include <iostream.h>
+#include <iostream>
#if X11
-#include <strstream.h>
+#include <sstream>
#include <time.h>
#endif
#if WIN32
@@ -266,43 +266,39 @@
void Role::error(const char *msg1,const char *msg2,const char *msg3) {
- ostrstream str;
+ stringstream str;
if (msg2 == NULL) {
- str << msg1 << ends;
+ str << msg1;
}
else if (msg3 == NULL) {
- str << msg1 << msg2 << ends;
+ str << msg1 << msg2;
}
else {
- str << msg1 << msg2 << msg3 << ends;
+ str << msg1 << msg2 << msg3;
}
// Call one argument version.
- _error(str.str());
-
- delete str.str();
+ _error(str.str().c_str());
}
void Role::message(const char *msg1,const char *msg2,const char *msg3) {
- ostrstream str;
+ stringstream str;
if (msg2 == NULL) {
- str << msg1 << ends;
+ str << msg1;
}
else if (msg3 == NULL) {
- str << msg1 << msg2 << ends;
+ str << msg1 << msg2;
}
else {
- str << msg1 << msg2 << msg3 << ends;
+ str << msg1 << msg2 << msg3;
}
// Call one argument version.
- _message(str.str());
-
- delete str.str();
+ _message(str.str().c_str());
}
@@ -605,11 +601,11 @@
// Display message that we are looking up IP address.
// Assumes that caller will call Client::connect_server after a turn or two,
// so the message will be displayed on the Ui.
- ostrstream str;
- str << "Looking up IP address for server " << serverName << ends;
+ stringstream str;
+ str << "Looking up IP address for server " << serverName;
// Display for a long time.
- errLocator->arena_message_enq(str.str(),NULL,1000000);
- errLocator->message_enq(Utils::strdup(str.str()));
+ errLocator->arena_message_enq(Utils::strdup(str.str().c_str()),NULL,1000000);
+ errLocator->message_enq(Utils::strdup(str.str().c_str()));
// Probably would be better to use Role::message(), but we want it to stay
// up for a long time. Should add argument to Role::message().
@@ -663,12 +659,10 @@
}
}
if (n == CLIENT_PORT_TRIES) {
- ostrstream str;
+ stringstream str;
str << "Could not bind local UDP port to any of "
- << clientPortBase << "-" << (clientPortBase + CLIENT_PORT_TRIES - 1)
- << ends;
- error(str.str());
- delete str.str();
+ << clientPortBase << "-" << (clientPortBase + CLIENT_PORT_TRIES - 1);
+ error(str.str().c_str());
return;
}
// cout << "UDP port seems to be" << client.sin_port << endl;
@@ -703,22 +697,19 @@
// Inform user of failed connection
if (!ok()) {
- strstream msg;
+ stringstream msg;
msg << "Could not connect to " << serverName << " on port " <<
- port << "." << ends;
- error(msg.str());
- delete(msg.str());
+ port << ".";
+ error(msg.str().c_str());
delete tcpOut;
return;
}
// Inform user of successful connection
- strstream msg;
+ stringstream msg;
msg << hostName << " connected to " << serverName << " on port " <<
- port << ends;
- message(msg.str());
- delete msg.str();
-
+ port;
+ message(msg.str().c_str());
// Create TCP and UDP streams.
tcpIn = new NetInStream(tcpSock,False);
@@ -967,11 +958,11 @@
Role::_error(msg);
if (errorLocator) {
- ostrstream str2;
- str2 << "ERROR: " << msg << ends;
- errorLocator->arena_message_enq(str2.str(),NULL,ROLE_FAILED_TIME);
+ stringstream str2;
+ str2 << "ERROR: " << msg;
+ errorLocator->arena_message_enq(Utils::strdup(str2.str().c_str()),NULL,ROLE_FAILED_TIME);
// Don't delete str2.str(), give memory to the Locator.
- errorLocator->message_enq(Utils::strdup(str2.str()));
+ errorLocator->message_enq(Utils::strdup(str2.str().c_str()));
}
#if WIN32
// Only the client can afford to block on error messages.
@@ -986,11 +977,9 @@
Role::_error(msg);
if (errorLocator) {
- ostrstream str2;
- str2 << msg << ends;
- errorLocator->arena_message_enq(str2.str());
+ errorLocator->arena_message_enq(Utils::strdup(msg));
// Don't delete str2.str(), give memory to the Locator.
- errorLocator->message_enq(Utils::strdup(str2.str()));
+ errorLocator->message_enq(Utils::strdup(msg));
}
}
@@ -1256,10 +1245,9 @@
if (turn > turnMax) {
turnMax = turn;
if (echoPingPong) {
- ostrstream str;
- str << "PONG the server with turn " << turnMax << ends;
- message(str.str());
- delete str.str();
+ stringstream str;
+ str << "PONG the server with turn " << turnMax;
+ message(str.str().c_str());
}
// Tell server so it can free turn windows to send more data.
XETP::send_pong(udpOut,turnMax);
@@ -1365,10 +1353,9 @@
}
}
else {
- ostrstream str;
- str << "No context for classId " << classId << ends;
- error(str.str());
- delete str.str();
+ stringstream str;
+ str << "No context for classId " << classId;
+ error(str.str().c_str());
}
}
}
@@ -1582,9 +1569,9 @@
return Utils::strdup(clientName);
}
- ostrstream str;
- str << '\"' << intel->get_name() << "\"@" << clientName << ends;
- return str.str();
+ stringstream str;
+ str << '\"' << intel->get_name() << "\"@" << clientName;
+ return Utils::strdup(str.str().c_str());
}
@@ -1695,11 +1682,10 @@
}
#ifdef SKIP_MESSAGES
- ostrstream msg;
+ stringstream msg;
msg << "Average delay is " << avg << " out of "
- << delaysNum << " samples." << ends;
+ << delaysNum << " samples.";
server->message(msg.str());
- delete msg.str();
#endif
#if 0
@@ -1723,10 +1709,9 @@
// server->error("Client has reached maximum skip value.");
// }
#ifdef SKIP_MESSAGES
- ostrstream msg;
- msg << "Increasing skip to " << skip << ends;
+ stringstream msg;
+ msg << "Increasing skip to " << skip;
server->message(msg.str());
- delete msg.str();
#endif
}
// We have moved back into our target range, can send more data now.
@@ -1734,10 +1719,9 @@
skip--;
#ifdef SKIP_MESSAGES
- ostrstream msg;
- msg << "Decreasing skip to " << skip << ends;
+ stringstream msg;
+ msg << "Decreasing skip to " << skip;
server->message(msg.str());
- delete msg.str();
#endif
}
@@ -1777,7 +1761,7 @@
-Server::Server(Boolean lHuman,char *portName,LocatorP errLocator) {
+Server::Server(Boolean lHuman,const char *portName,LocatorP errLocator) {
// Hack, using errLocator for more than reporting errors.
errLocator->set_remember_deleted(True);
errLocator->set_remember_sounds(True);
@@ -1843,19 +1827,17 @@
// Give address to both the TCP and UDP sockets.
if (bind(tcpSock, (CMN_SOCKADDR *)&serverAddr, sizeof(serverAddr)) < 0) {
- ostrstream str;
+ stringstream str;
str << "Couldn't bind socket name to TCP socket on port "
- << port << "." << ends;
- error(str.str());
- delete str.str();
+ << port << ".";
+ error(str.str().c_str());
return;
}
if (bind(udpSock, (CMN_SOCKADDR *)&serverAddr, sizeof(serverAddr)) < 0) {
- ostrstream str;
+ stringstream str;
str << "Couldn't bind socket name to UDP socket on port "
- << port << "." << ends;
- error(str.str());
- delete str.str();
+ << port << ".";
+ error(str.str().c_str());
return;
}
@@ -1868,10 +1850,9 @@
assert(udpIn);
// Message to server log.
- strstream msg;
- msg << "Set up server on port " << port << ends;
- message(msg.str());
- delete(msg.str());
+ stringstream msg;
+ msg << "Set up server on port " << port;
+ message(msg.str().c_str());
running = True;
}
@@ -1951,10 +1932,9 @@
localHumanId = hId;
// Log the human's name.
- strstream msg;
- msg << "Player 0 \"" << human->get_name() << '\"' << "@SERVER" << ends;
- message(msg.str());
- delete(msg.str());
+ stringstream msg;
+ msg << "Player 0 \"" << human->get_name() << '\"' << "@SERVER";
+ message(msg.str().c_str());
return;
}
@@ -1985,12 +1965,11 @@
// Log all the players in the game, some code duplication for the
// local human.
- ostrstream str;
+ stringstream str;
char* fullName = cn->get_full_client_name();
- str << "Player " << num << " " << fullName << ends;
- message(str.str());
+ str << "Player " << num << " " << fullName;
+ message(str.str().c_str());
delete fullName;
- delete str.str();
// Send assign_intel via TCP
OutStreamP out = cn->get_tcp_out_stream();
@@ -2007,13 +1986,12 @@
// anyway.
for (m = 0; m < connections.length() && m != n; m++) {
char* fullName = cn->get_full_client_name();
- ostrstream str;
- str << fullName << " has joined the game" << ends;
+ stringstream str;
+ str << fullName << " has joined the game";
delete fullName;
OutStreamP out = cn->get_udp_out_stream();
- XETP::send_arena_message(out,timeMS,str.str());
- delete str.str();
+ XETP::send_arena_message(out,timeMS,str.str().c_str());
}
cn->creation_message_sent();
}
@@ -2101,13 +2079,12 @@
// Give the connection some slack when it is first starting up.
turn - cn->get_start_turn() >= MINIMUM_CUTOFF) {
char* fullName = cn->get_full_client_name();
- ostrstream str;
+ stringstream str;
str << fullName
<< " has not responded in "
- << diff << " turns. Disconnect." << ends;
- message(str.str());
+ << diff << " turns. Disconnect.";
+ message(str.str().c_str());
delete fullName;
- delete str.str();
tooOld = True;
}
}
@@ -2147,11 +2124,10 @@
diff == NO_ACTIVITY_WARN_2 ||
diff == NO_ACTIVITY_WARN_3) {
if (echoPingPong) {
- ostrstream str;
+ stringstream str;
str << "Haven't heard from " << cn->get_client_name()
- << " in " << diff << " turns, sending PING." << ends;
- message(str.str());
- delete str.str();
+ << " in " << diff << " turns, sending PING.";
+ message(str.str().c_str());
}
XETP::send_ping(cn->get_udp_out_stream());
}
@@ -2311,7 +2287,11 @@
for (m = 0; m < followers.length(); m++) {
PhysicalP q = (PhysicalP)followers.get(m);
netData = q->get_net_data();
- assert(!netData->get_sent_flag());
+ // This line was aborting network games, often in the pound scenario.
+ // Without it, the server seems to continue without error.
+ // I tried replacing it with a warning, but there is so much of it
+ // that it is nearly impossible to see anything else. -Brandon
+// assert(!netData->get_sent_flag());
netData->set_sent_flag(True);
}
@@ -2713,9 +2693,9 @@
// Careful to set the propagate flag to False so the message doesn't get
// sent to the clients.
if (errorLocator) {
- ostrstream str2;
- str2 << "SERVER: " << msg << ends;
- errorLocator->arena_message_enq(str2.str(),NULL,ROLE_FAILED_TIME,False);
+ stringstream str2;
+ str2 << "SERVER: " << msg;
+ errorLocator->arena_message_enq(Utils::strdup(str2.str().c_str()),NULL,ROLE_FAILED_TIME,False);
// Don't delete str2.str(), give memory to the Locator.
// Could do a regular message_enq(), but would have to deal with the
@@ -2728,10 +2708,9 @@
void Server::display_chat_message(LocatorP l,const char* sender,
const char* msg) {
// Log the chat message, then let Role handle it.
- strstream logMsg;
- logMsg << '<' << sender << '>' << msg << ends;
- message(logMsg.str());
- delete logMsg.str();
+ stringstream logMsg;
+ logMsg << '<' << sender << '>' << msg;
+ message(logMsg.str().c_str());
Role::display_chat_message(l,sender,msg);
}
@@ -2851,12 +2830,11 @@
udpAddr->sin_port = htons(udpPort);
// Log the connection.
- strstream msg;
+ stringstream msg;
msg << clientName <<
" connected (TCP port " << ntohs(tcpAddr.sin_port) <<
- ", UDP port " << udpPort << ")" << ends;
- message(msg.str());
- delete(msg.str());
+ ", UDP port " << udpPort << ")";
+ message(msg.str().c_str());
Connection* cn =
new Connection(this,errorLocator,
@@ -2874,7 +2852,7 @@
XETP::send_reset(out,manager->get_game_style_type());
// Say hello to the new client.
- ostrstream greeting;
+ stringstream greeting;
greeting << "Welcome to " << hostName << ".";
if (get_humans_num() == 1) {
@@ -2884,10 +2862,8 @@
greeting << " There are now "
<< get_humans_num() << " players.";
}
- greeting << ends;
int timeMS = quantaToMS(UI_ARENA_MESSAGE_TIME,manager);
- XETP::send_arena_message(out,timeMS,greeting.str());
- delete greeting.str();
+ XETP::send_arena_message(out,timeMS,greeting.str().c_str());
manager->humans_num_incremented();
}
@@ -2918,18 +2894,16 @@
Connection* cm = get_connection(m);
char* fullName = cn->get_full_client_name();
- ostrstream str;
+ stringstream str;
str << fullName << " has disconnected";
if (intel) {
str << ", " << kills << " human kills";
}
- str << ends;
XETP::send_arena_message(cm->get_udp_out_stream(),
- timeMS,str.str());
+ timeMS,str.str().c_str());
delete fullName;
- delete str.str();
}
}
@@ -3262,8 +3236,8 @@
void Server::send_udp_server_pong(IGameManager* manager,LocatorP locator,
CMN_SOCKET udpSock,
CMN_SOCKADDR_IN* destAddr) {
- static char* unknownString = "<unknown>";
- static char* serverString = "<server>";
+ static const char* unknownString = "<unknown>";
+ static const char* serverString = "<server>";
// Temporary stream.
|