summaryrefslogtreecommitdiff
path: root/games/xevil/files/patch-x11__serverping.cpp
blob: debc89bafc73591504388ad15542890956b88371 (plain) (blame)
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
--- x11/serverping.cpp.orig	2012-05-27 06:52:29.000000000 +0900
+++ x11/serverping.cpp	2012-05-27 07:12:12.000000000 +0900
@@ -25,14 +25,15 @@
 // code and should be reasonably easy to compile on Windows.
 
 
-#include <iostream.h>
-#include <strstream.h>
+#include <iostream>
+#include <sstream>
 #include "utils.h"
 #include "streams.h"
 #include "xetp_basic.h"
 #include "neth.h"
 #include "id.h"
 
+using namespace std;
 
 
 class ServerPing {
@@ -113,7 +114,7 @@
 
 
   char* sString = argv[argc - 1];
-  char* port = Utils::strchr(sString,':');
+  const char* port = Utils::strchr(sString,':');
   // server:port
   if (port) {
     serverName = new char[port - sString + 1];
@@ -140,10 +141,9 @@
     error("Error opening client UDP socket.");
   }
   
-  ostrstream str;
-  str << "Looking up IP address for server " << serverName << ends;
-  message(str.str());
-  delete str.str();
+  stringstream str;
+  str << "Looking up IP address for server " << serverName;
+  message(str.str().c_str());
 
   // Create server address.
   memset((void *)&serverAddr,'\0',sizeof(serverAddr));
@@ -171,10 +171,9 @@
   client.sin_addr.s_addr = htonl(INADDR_ANY);
   client.sin_port = htons((u_short)clientPort);
   if (bind(udpSock,(CMN_SOCKADDR *)&client,sizeof(client)) < 0) {
-    ostrstream str;
-    str << "Could not bind local UDP port " << clientPort << ends;
-    error(str.str());
-    delete str.str();
+    stringstream str;
+    str << "Could not bind local UDP port " << clientPort;
+    error(str.str().c_str());
     return;
   }
 
@@ -197,11 +196,10 @@
   // Send "count" number of SERVER_PINGs.
   for (int tries = 0; tries < count; tries++) {
     // Send the ping.
-    ostrstream msg;
+    stringstream msg;
     msg << "Sending XETP::SERVER_PING to " 
-        << serverName << ':' << serverPort << ends;
-    message(msg.str());
-    delete msg.str();
+        << serverName << ':' << serverPort;
+    message(msg.str().c_str());
     XETPBasic::send_server_ping(udpOut);
     // Don't buffer the ping.
     udpOut->flush();
@@ -248,11 +246,10 @@
   }
 
   // If we get here, we failed to reach the server.
-  ostrstream msg;
+  stringstream msg;
   msg << "No return from " << serverName << ':' << serverPort << " after " 
-      << count << " tries." << ends;
-  error(msg.str());
-  delete msg.str();
+      << count << " tries.";
+  error(msg.str().c_str());
 }
 
 
@@ -271,12 +268,9 @@
 
 
 void ServerPing::error(const char* msg1,const char* msg2) {
-  ostrstream str;
-  str << msg1 << msg2 << ends;
-  error(str.str());
-
-  // Will never get here, but WTF.
-  delete str.str();
+  stringstream str;
+  str << msg1 << msg2;
+  error(str.str().c_str());
 }
 
 
@@ -355,6 +349,7 @@
 
 
 
+int
 main(int argc,char** argv) {
   ServerPing ping(argc,argv);
   ping.go();