Thomas Buck 10 лет назад
Родитель
Сommit
dbe7bb3e56
10 измененных файлов: 4 добавлений и 1126 удалений
  1. 1
    0
      ChangeLog
  2. 0
    10
      README.md
  3. 0
    6
      data/OpenRaider.init
  4. 0
    112
      include/Network.h
  5. 0
    2
      include/OpenRaider.h
  6. 0
    1
      src/CMakeLists.txt
  7. 0
    698
      src/Network.cpp
  8. 2
    187
      src/OpenRaider.cpp
  9. 1
    14
      test/CMakeLists.txt
  10. 0
    96
      test/Network.cpp

+ 1
- 0
ChangeLog Просмотреть файл

@@ -11,6 +11,7 @@
11 11
 	* Moved system_timer into time utilities, changed its API
12 12
 	* Fixed a bug that prevented input of console commands using
13 13
 	  the shift key for eg. uppercase letters or symbols
14
+	* Removed (totally unfinished) networking support
14 15
 
15 16
 	[ 20140306 ]
16 17
 	* Created utility library

+ 0
- 10
README.md Просмотреть файл

@@ -131,16 +131,6 @@ If you want to change this behaviour, this happens around line 1075 of `src/Open
131 131
 Console commands (BOOL is now '0' or '1' for less typing).
132 132
 Pressing <UP> will go back to last command entered (saves typing).
133 133
 
134
-#### Network
135
-
136
-| Command          | Action                                |
137
-| ----------------:|:------------------------------------- |
138
-| server           | Start network listen server           |
139
-| killserver       | Stop network listen server            |
140
-| port INT         | Set network port number               |
141
-| connect HOSTNAME | Connect to network server at HOSTNAME |
142
-| disconnect       | Disconnect from network server        |
143
-
144 134
 #### Game
145 135
 
146 136
 | Command             | Action                                                 |

+ 0
- 6
data/OpenRaider.init Просмотреть файл

@@ -11,12 +11,6 @@ Font=~/.OpenRaider/data/test.ttf
11 11
 [Audio.OpenAL]
12 12
 Enable=true
13 13
 
14
-[Network.Server]
15
-Enable=false
16
-#Name=OpenRaider Server Beta 1
17
-#Dedicated=true
18
-Port=27910
19
-
20 14
 [Input.Mouse]
21 15
 SensitivityX=1.0
22 16
 SensitivityY=1.0

+ 0
- 112
include/Network.h Просмотреть файл

@@ -1,112 +0,0 @@
1
-/*!
2
- * \file include/Network.h
3
- * \brief Networking Singleton class
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#ifndef _NETWORK_H_
9
-#define _NETWORK_H_
10
-
11
-/*!
12
- * \brief The packet holds the data for the network.
13
- *
14
- * This is encapsulated in the frame.
15
- */
16
-typedef struct network_packet_s {
17
-    char send;
18
-    unsigned int port;
19
-    unsigned int cid;
20
-    char  data[32];    //!< A short (32 char) string
21
-    float pos[3];
22
-    float pitch;
23
-    float yaw;
24
-    int aframe;
25
-    int bframe;
26
-    int view_model;
27
-    char gurantee;     //!< TCP like
28
-} network_packet_t;
29
-
30
-/*!
31
- * \brief The frame holds the data for the datalink layer.
32
- *
33
- * This goes over the line.
34
- */
35
-typedef struct network_frame_s {
36
-    unsigned int header;   //!< The header flags
37
-    unsigned int seq;      //!< The sequence number
38
-    unsigned int uid;
39
-    network_packet_t data; //!< The packet for the NL
40
-} network_frame_t;
41
-
42
-void from_network_layer(network_packet_t *p, unsigned int *last_id);
43
-void to_network_layer(network_packet_t p);
44
-
45
-void killNetworkSingleton();
46
-
47
-#define REMOTE_HOST_STR_SZ 64
48
-#define BIND_HOST_STR_SZ 64
49
-
50
-/*!
51
- * \brief Networking Singleton class
52
- */
53
-class Network {
54
-public:
55
-    /*!
56
-     * \brief Get the Singleton or create it on first use
57
-     * \returns Singleton of type Network
58
-     */
59
-    static Network *Instance();
60
-
61
-    /*!
62
-     * \brief Deconstructs an object of Network
63
-     */
64
-    ~Network();
65
-
66
-    network_frame_t &getPiggyBack();
67
-
68
-    unsigned int getUID();
69
-
70
-    int getPort();
71
-
72
-    void setDebug(bool toggle);
73
-
74
-    void setPort(unsigned int port);
75
-
76
-    void setBindHost(char *s);
77
-
78
-    void setRemoteHost(char *s);
79
-
80
-    void killServerThread();
81
-
82
-    void killClientThread();
83
-
84
-    void spawnServerThread();
85
-
86
-    void spawnClientThread();
87
-
88
-    int runServer();
89
-
90
-    void runClient();
91
-
92
-protected:
93
-    /*!
94
-     * \brief Constructs an object of Network
95
-     */
96
-    Network();
97
-
98
-private:
99
-    static Network *mInstance;            //!< Singleton use
100
-    bool mSpawnedClient;
101
-    bool mSpawnedServer;
102
-    int mPort;
103
-    char mRemoteHost[REMOTE_HOST_STR_SZ];
104
-    char mBindHost[BIND_HOST_STR_SZ];
105
-    bool mPiggyBack;
106
-    bool mNetworkReliable;
107
-    bool mKillClient;
108
-    bool mKillServer;
109
-    bool mDebug;
110
-};
111
-
112
-#endif

+ 0
- 2
include/OpenRaider.h Просмотреть файл

@@ -16,7 +16,6 @@
16 16
 #include "Render.h"
17 17
 #include "Sound.h"
18 18
 #include "SDLSystem.h"
19
-#include "Network.h"
20 19
 #include "World.h"
21 20
 #include "templates/List.h"
22 21
 #include "templates/Vector.h"
@@ -226,7 +225,6 @@ private:
226 225
     char *m_pakDir;              //!< Current pak directory
227 226
     char *m_audioDir;            //!< Current audio directory
228 227
     char *m_homeDir;             //!< Current home directory
229
-    Vector<entity_t *> mClients; //!< Player entity/clients
230 228
 };
231 229
 
232 230
 #endif

+ 0
- 1
src/CMakeLists.txt Просмотреть файл

@@ -4,7 +4,6 @@ set (SRCS ${SRCS} "Emitter.cpp")
4 4
 set (SRCS ${SRCS} "GLString.cpp")
5 5
 set (SRCS ${SRCS} "Matrix.cpp")
6 6
 set (SRCS ${SRCS} "Mesh.cpp")
7
-set (SRCS ${SRCS} "Network.cpp")
8 7
 set (SRCS ${SRCS} "OpenRaider.cpp")
9 8
 set (SRCS ${SRCS} "Particle.cpp")
10 9
 set (SRCS ${SRCS} "Quaternion.cpp")

+ 0
- 698
src/Network.cpp Просмотреть файл

@@ -1,698 +0,0 @@
1
-/*!
2
- * \file src/Network.cpp
3
- * \brief Networking Singleton class
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <unistd.h>
9
-#include <signal.h>
10
-#include <string.h>
11
-#include <time.h>
12
-#include <sys/time.h>
13
-#include <errno.h>
14
-#include <strings.h>
15
-#include <stdio.h>
16
-#include <sys/types.h>
17
-#include <sys/socket.h>
18
-#include <netinet/in.h>
19
-#include <netdb.h>
20
-#include <arpa/inet.h>
21
-#include <stdlib.h>
22
-
23
-#include "utils/math.h" // Random Number
24
-#include "Network.h"
25
-
26
-//#define LOCAL_BCAST
27
-#define MAX_CLIENTS 32
28
-
29
-typedef struct client_s {
30
-    unsigned int uid;
31
-    char active;
32
-    unsigned int seq;
33
-    unsigned int frameExpected;
34
-} client_t;
35
-
36
-#include <pthread.h>
37
-pthread_t gPThreadId[3];
38
-
39
-unsigned int gUID;
40
-client_t gClients[MAX_CLIENTS];
41
-unsigned int gNumClients = 0;
42
-network_frame_t gPiggyBack;
43
-
44
-
45
-////////////////////////////////////////////////////////////
46
-// Constructors
47
-////////////////////////////////////////////////////////////
48
-
49
-Network *Network::mInstance = 0x0;
50
-
51
-
52
-Network *Network::Instance()
53
-{
54
-    if (mInstance == 0x0)
55
-    {
56
-        mInstance = new Network();
57
-    }
58
-
59
-    return mInstance;
60
-}
61
-
62
-
63
-void killNetworkSingleton()
64
-{
65
-    printf("Shutting down Network...\n");
66
-
67
-    // Requires public deconstructor
68
-    delete Network::Instance();
69
-}
70
-
71
-
72
-Network::Network()
73
-{
74
-    strncpy(mRemoteHost, "localhost", REMOTE_HOST_STR_SZ);
75
-    memset(mBindHost, 0, BIND_HOST_STR_SZ);
76
-    setPort(8080);
77
-
78
-    mPiggyBack = true;
79
-    mNetworkReliable = true;
80
-    mSpawnedClient = false;
81
-    mSpawnedServer = false;
82
-    mKillClient = false;
83
-    mKillServer = false;
84
-    mDebug = false;
85
-
86
-    gUID = getUID();
87
-
88
-    printf("UID %u\n", gUID);
89
-
90
-    for (gNumClients = MAX_CLIENTS; gNumClients > 0;)
91
-    {
92
-        --gNumClients;
93
-
94
-        gClients[gNumClients].active = 0;
95
-        gClients[gNumClients].uid = 0;
96
-        gClients[gNumClients].seq = 0;
97
-    }
98
-}
99
-
100
-
101
-Network::~Network()
102
-{
103
-    killServerThread();
104
-    killClientThread();
105
-}
106
-
107
-
108
-////////////////////////////////////////////////////////////
109
-// Public Accessors
110
-////////////////////////////////////////////////////////////
111
-
112
-network_frame_t &Network::getPiggyBack()
113
-{
114
-    return gPiggyBack;
115
-}
116
-
117
-
118
-unsigned int Network::getUID()
119
-{
120
-    struct timeval tv;
121
-    struct timezone tz;
122
-
123
-
124
-    gettimeofday(&tv, &tz);
125
-
126
-    srand(tv.tv_usec);
127
-
128
-    return ((unsigned int)(tv.tv_sec * helRandomNum(2.0f, 3.3f) -
129
-                tv.tv_sec * helRandomNum(1.0f, 2.0f)) +
130
-            (unsigned int)(tv.tv_usec * helRandomNum(2.0f, 3.3f) -
131
-                tv.tv_usec * helRandomNum(1.0f, 2.0f)) +
132
-            (unsigned int)helRandomNum(666.0f, 5000.0f));
133
-}
134
-
135
-
136
-int Network::getPort()
137
-{
138
-    return mPort;
139
-}
140
-
141
-
142
-////////////////////////////////////////////////////////////
143
-// Public Mutators
144
-////////////////////////////////////////////////////////////
145
-
146
-void *client_thread(void *v)
147
-{
148
-    Network &network = *Network::Instance();
149
-    network.runClient();
150
-
151
-    return NULL;
152
-}
153
-
154
-
155
-void *server_thread(void *v)
156
-{
157
-    Network &network = *Network::Instance();
158
-    network.runServer();
159
-
160
-    return NULL;
161
-}
162
-
163
-
164
-void Network::setBindHost(char *s)
165
-{
166
-    if (!s || !s[0])
167
-        return;
168
-
169
-    strncpy(mBindHost, s, BIND_HOST_STR_SZ);
170
-}
171
-
172
-
173
-void Network::setRemoteHost(char *s)
174
-{
175
-    if (!s || !s[0])
176
-        return;
177
-
178
-    strncpy(mRemoteHost, s, REMOTE_HOST_STR_SZ);
179
-}
180
-
181
-
182
-void Network::setDebug(bool toggle)
183
-{
184
-    mDebug = toggle;
185
-}
186
-
187
-
188
-void Network::setPort(unsigned int port)
189
-{
190
-    mPort = port;
191
-}
192
-
193
-
194
-void Network::killServerThread()
195
-{
196
-    mKillServer = true;
197
-
198
-    // Remember for mutex
199
-    //  while (mKillServer)
200
-    //  {
201
-    //  }
202
-
203
-    mSpawnedServer = false;
204
-}
205
-
206
-
207
-void Network::killClientThread()
208
-{
209
-    mKillClient = true;
210
-
211
-    // Remember for mutex
212
-    //  while (mKillClient)
213
-    //  {
214
-    //  }
215
-
216
-    mSpawnedClient = false;
217
-}
218
-
219
-
220
-void Network::spawnServerThread()
221
-{
222
-    // For now don't handle shutting down server to start client and vv
223
-    if (!mSpawnedServer && !mSpawnedClient)
224
-    {
225
-        pthread_create(gPThreadId + 0, 0, server_thread, NULL);
226
-        mSpawnedServer = true;
227
-    }
228
-}
229
-
230
-
231
-void Network::spawnClientThread()
232
-{
233
-    // For now don't handle shutting down server to start client and vv
234
-    if (!mSpawnedServer && !mSpawnedClient)
235
-    {
236
-        pthread_create(gPThreadId + 1, 0, client_thread, NULL);
237
-        mSpawnedClient = true;
238
-    }
239
-}
240
-
241
-
242
-////////////////////////////////////////////////////////////
243
-// Protected Mutators
244
-////////////////////////////////////////////////////////////
245
-
246
-int Network::runServer()
247
-{
248
-    unsigned int fsize;
249
-    int socket_fd, cc, cip;
250
-    struct sockaddr_in s_in, from;
251
-    char hostid[64];
252
-    network_frame_t f;
253
-    unsigned int i;
254
-    unsigned int packetsRecieved = 0;
255
-
256
-
257
-    socket_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
258
-
259
-    if (socket_fd < 0)
260
-    {
261
-        perror("recv_udp:socket");
262
-        return -1;
263
-    }
264
-
265
-    if (mBindHost[0])
266
-    {
267
-        strncpy(hostid, mBindHost, 64);
268
-    }
269
-    else
270
-    {
271
-        if (gethostname(hostid, 64) < 0)
272
-        {
273
-            perror("Server: recv_udp:gethostname");
274
-            return -1;
275
-        }
276
-
277
-        printf("Server: gethostname returned '%s'\n", hostid);
278
-        fflush(stdout);
279
-    }
280
-
281
-    // Setup for port binding
282
-    memset(&s_in, 0, sizeof(s_in));
283
-    s_in.sin_family = AF_INET;
284
-#ifdef LOCAL_BCAST
285
-    // Replace deprecated gethostbyname() with getaddrinfo()
286
-    //struct hostent *hostptr;
287
-    //if ((hostptr = gethostbyname(hostid)) == NULL)
288
-    //{
289
-    //    fprintf(stderr, "Server: recv_udp, Invalid host name '%s'\n", hostid);
290
-    //    return -1;
291
-    //}
292
-    //memcpy((void *)(&s_in.sin_addr), hostptr->h_addr, hostptr->h_length);
293
-    struct addrinfo *result, *res;
294
-    bool found = false;
295
-    int error = getaddrinfo(hostid, NULL, NULL, &result);
296
-    if (error != 0) {
297
-        fprintf(stderr, "Server: %s\n", gai_strerror(error));
298
-        return -1;
299
-    }
300
-    for (res = result; res != NULL; res = res->ai_next) {
301
-        if (res->ss_family == AF_INET) {
302
-            found = true;
303
-            memcpy((void *)&s_in, res->ai_addr, res->ai_addrlen);
304
-            break; // Found something suitable
305
-        }
306
-    }
307
-    freeaddrinfo(result);
308
-    if (!found) {
309
-        fprintf(stderr, "Server: Can't bind to %s\n", hostid);
310
-        return -1;
311
-    }
312
-#else
313
-    s_in.sin_addr.s_addr = htonl(INADDR_ANY);
314
-#endif
315
-    int port = getPort();
316
-    s_in.sin_port = htons(port); // htons new
317
-
318
-    fflush(stdout);
319
-
320
-    // Bind
321
-    while (bind(socket_fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0)
322
-    {
323
-        if (s_in.sin_port++ > (port + 10))
324
-        {
325
-            perror("Server: recv_udp:bind exhausted");
326
-            return -1;
327
-        }
328
-    }
329
-
330
-    cip = ntohl(s_in.sin_addr.s_addr);
331
-
332
-    printf("Server: Started on ( %i.%i.%i.%i:%i )\n",
333
-            cip >> 24, cip << 8 >> 24,
334
-            cip << 16 >> 24, cip << 24 >> 24, s_in.sin_port);
335
-
336
-    for (; !mKillClient;)
337
-    {
338
-        fsize = sizeof(from);
339
-
340
-        // 1. Wait for event
341
-        // 2. Get inbound frame
342
-        cc = recvfrom(socket_fd, &f, sizeof(network_frame_t), 0,
343
-                (struct sockaddr *)&from, &fsize);
344
-
345
-        if (cc < 0)
346
-        {
347
-            perror("Server: recv_udp:recvfrom");
348
-            continue;
349
-        }
350
-
351
-        ++packetsRecieved;
352
-
353
-        if (mDebug)
354
-        {
355
-            printf("=====================================================\n");
356
-            printf("Packet %u\n", packetsRecieved);
357
-            printf("Server: Recieved packet from %u\n",
358
-                    f.uid);
359
-        }
360
-
361
-        // A. Look and see if this client has connected before
362
-        for (i = 0; i < gNumClients; ++i)
363
-        {
364
-            if (gClients[i].uid == f.uid)
365
-            {
366
-                break;
367
-            }
368
-        }
369
-
370
-        // B. Collect client data if it's a new connection
371
-        if (!gClients[i].active)
372
-        {
373
-            for (i = 0; i < gNumClients+1; ++i)
374
-            {
375
-                if ((i + 1) < MAX_CLIENTS && !gClients[i].active)
376
-                {
377
-                    gClients[i].uid = f.uid;
378
-                    gClients[i].active = 1;
379
-                    gClients[i].frameExpected = 0;
380
-                    ++gNumClients;
381
-
382
-                    printf("Server: %u made connection, as client %u\n",
383
-                            gClients[i].uid, i);
384
-                    break;
385
-                }
386
-            }
387
-
388
-            if (i == MAX_CLIENTS || !gClients[i].active)
389
-            {
390
-                if (mDebug)
391
-                {
392
-                    printf("Server: Handshake packet from %u failed?\n",
393
-                            f.uid);
394
-                }
395
-                continue;
396
-            }
397
-        }
398
-
399
-        cip = ntohl(from.sin_addr.s_addr);
400
-
401
-        if (mDebug)
402
-        {
403
-            printf("Server: Client (Famliy %d, Address %i.%i.%i.%i:%d)\n",
404
-                    ntohs(from.sin_family), cip >> 24, cip << 8 >> 24,
405
-                    cip << 16 >> 24, cip << 24 >> 24,
406
-                    ntohs(from.sin_port));
407
-
408
-            printf("Server: Datalink layer recieved: packet seq %u\n",
409
-                    f.seq);
410
-        }
411
-
412
-        if (mNetworkReliable)
413
-        {
414
-            if (f.seq == gClients[i].seq)
415
-            {
416
-                if (mDebug)
417
-                {
418
-                    printf("SERVER> Msg from %u\n", f.uid);
419
-                }
420
-
421
-                to_network_layer(f.data);
422
-                gClients[i].seq = f.seq;
423
-            }
424
-            else
425
-            {
426
-                continue;
427
-            }
428
-        }
429
-
430
-        //! \fixme Combine with above, duh
431
-        // 3. Send to network layer
432
-        if (gClients[i].frameExpected == f.header)
433
-        {
434
-            f.data.cid = i;
435
-
436
-            to_network_layer(f.data);
437
-            gClients[i].frameExpected = !gClients[i].frameExpected;
438
-        }
439
-
440
-        fflush(stdout);
441
-
442
-#ifdef UNIT_TEST
443
-        if ((rand() % 10 == 0))
444
-        {
445
-            printf("Server: Simulating a lost ack %u\n", f.seq);
446
-            continue;
447
-        }
448
-#endif
449
-
450
-        // 4. Send ACK, w/ piggyback if requested
451
-        if (mPiggyBack)
452
-        {
453
-            gPiggyBack.header = 0;
454
-            gPiggyBack.seq = f.seq;
455
-            gPiggyBack.uid = gUID;
456
-
457
-            if (mDebug)
458
-            {
459
-                printf("SERVER> Sending data by piggyback\n");
460
-            }
461
-
462
-            cc = sendto(socket_fd, &gPiggyBack, sizeof(gPiggyBack), 0,
463
-                    (struct sockaddr *)&from, sizeof(from));
464
-        }
465
-        else
466
-        {
467
-            f.header = 0;
468
-            f.seq = 0;
469
-            f.uid = gUID;
470
-
471
-            cc = sendto(socket_fd, &f, sizeof(f), 0,
472
-                    (struct sockaddr *)&from, sizeof(from));
473
-        }
474
-
475
-        if (cc < 0)
476
-        {
477
-            perror("Server: send_udp:sendto");
478
-        }
479
-        else
480
-        {
481
-            if (mDebug)
482
-            {
483
-                printf("Server: Ack sent to %u\n", gClients[i].uid);
484
-            }
485
-        }
486
-    }
487
-
488
-    mKillClient = false;
489
-
490
-    return 0;
491
-}
492
-
493
-
494
-void Network::runClient()
495
-{
496
-    unsigned int fsize, last_frame_sent = 0;
497
-    int socket_fd, cc, done;
498
-    struct sockaddr_in dest;
499
-    struct addrinfo *addr;
500
-    network_frame_t f;
501
-    struct timeval timeout;
502
-    fd_set readfds;
503
-    unsigned int packetsSent = 0;
504
-    unsigned int seq = 0;
505
-    char timedOut = 1;
506
-
507
-    if (!mRemoteHost || !mRemoteHost[0])
508
-    {
509
-        return;
510
-    }
511
-
512
-    memset((char*) &timeout, 0, sizeof(timeout));
513
-    timeout.tv_sec = 5;
514
-
515
-    socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
516
-
517
-    if (socket_fd == -1)
518
-    {
519
-        perror("Client: send_udp: socket");
520
-        exit(0);
521
-    }
522
-
523
-    //if ((hostptr = gethostbyname(mRemoteHost)) == NULL)
524
-    //{
525
-    //    fprintf(stderr, "Client: send_udp: invalid host name, %s\n",
526
-    //            mRemoteHost);
527
-    //    exit(0);
528
-    //}
529
-
530
-    int error = getaddrinfo(mRemoteHost, NULL, NULL, &addr);
531
-    if (error != 0) {
532
-        fprintf(stderr, "Client: %s\n", gai_strerror(error));
533
-        exit(0);
534
-    }
535
-
536
-    // Setup connection
537
-    memset(&dest, 0, sizeof(dest));
538
-    dest.sin_family = AF_INET;
539
-    int port = getPort();
540
-    dest.sin_port = htons(port);
541
-#ifdef LOCAL_BCAST
542
-    //memcpy(hostptr->h_addr, (char *) &dest.sin_addr, hostptr->h_length);
543
-    bool found = false;
544
-    for (struct addrinfo *res = addr; res != NULL; res = res->ai_next) {
545
-        if (res->ss_family == AF_INET) {
546
-            found = true;
547
-            memcpy((void *)&dest.sin_addr, res->ai_addr.sin_addr, sizeof(res->ai_addr.sin_addr));
548
-            break; // Found something suitable
549
-        }
550
-    }
551
-    freeaddrinfo(addr);
552
-    if (!found) {
553
-        fprintf(stderr, "Client: Can't connect to %s\n", hostid);
554
-        return;
555
-    }
556
-#else
557
-    if (inet_pton(AF_INET, mRemoteHost, &dest.sin_addr) < 0)
558
-    {
559
-        perror("inet_pton");
560
-        return;
561
-    }
562
-#endif
563
-
564
-
565
-    // init
566
-    f.data.send = 0;
567
-    f.seq = 0;
568
-
569
-    for (; !mKillServer;)
570
-    {
571
-        ++packetsSent;
572
-
573
-        if (mDebug)
574
-        {
575
-            printf("=====================================================\n");
576
-            printf("Packet %u\n", packetsSent);
577
-        }
578
-
579
-        // 1. Get packet to send over wire
580
-        if (mNetworkReliable && timedOut && f.seq != seq)
581
-        {
582
-            if (mDebug)
583
-            {
584
-                printf("Client: Resending packet\n");
585
-            }
586
-        }
587
-        else
588
-        {
589
-            from_network_layer(&f.data, &last_frame_sent);
590
-
591
-            if (!f.data.send)
592
-            {
593
-                struct timespec tmp;
594
-                tmp.tv_sec = 0;
595
-                tmp.tv_nsec = 20000;
596
-                nanosleep(&tmp, NULL);
597
-                continue;
598
-            }
599
-        }
600
-
601
-        // 2. Copy to frame
602
-        f.seq = 0;//seq;  // 0 forces all packets to check out
603
-        f.uid = gUID;
604
-
605
-        // 3. Send over the wire
606
-        done = 0;
607
-        timedOut = 0;
608
-
609
-        while (!done)
610
-        {
611
-            if (mDebug)
612
-            {
613
-                printf("Client: Sending packet %u\n", f.seq);
614
-            }
615
-
616
-            cc = sendto(socket_fd, &f, sizeof(f), 0,
617
-                    (struct sockaddr *)&dest, sizeof(dest));
618
-
619
-            if (cc < 0)
620
-            {
621
-                perror("Client: send_udp:sendto");
622
-
623
-                if (errno == EMSGSIZE)
624
-                {
625
-                    printf("Client: packet was too large\n");
626
-                }
627
-            }
628
-            else
629
-            {
630
-                f.data.send = 0;
631
-            }
632
-
633
-            // Comment out this to enable more reliable service
634
-            done = 1;
635
-        }
636
-
637
-        // 4. Wait for +ack or resend
638
-        FD_ZERO(&readfds);
639
-
640
-        // Setup socket to listen on here
641
-        FD_SET(socket_fd, &readfds);
642
-
643
-        // Set timeout in milliseconds
644
-        timeout.tv_usec = 850;
645
-
646
-        cc = select(socket_fd + 1, &readfds, NULL, NULL, &timeout);
647
-
648
-        if ((cc < 0) && (errno != EINTR))
649
-        {
650
-            // there was an local error with select
651
-        }
652
-
653
-        if (cc == 0)
654
-        {
655
-            if (mDebug)
656
-            {
657
-                printf("Client: Timeout detected on packet %u\n", f.seq);
658
-            }
659
-            timedOut = 1;
660
-            continue;
661
-        }
662
-
663
-        // Clear header for recv use
664
-        f.header = 0;
665
-
666
-        fsize = sizeof(dest);
667
-        cc = recvfrom(socket_fd, &f, sizeof(f), 0,
668
-                (struct sockaddr *)&dest, &fsize);
669
-
670
-        if (cc < 0)
671
-        {
672
-            perror("Client: recv_udp:recvfrom");
673
-        }
674
-        else
675
-        {
676
-            if (mDebug)
677
-            {
678
-                printf("Client: Datalink layer recieved: packet seq %u\n", f.seq);
679
-                printf("CLIENT> Msg from %u\n", f.uid);
680
-            }
681
-
682
-            to_network_layer(f.data);
683
-        }
684
-
685
-        if (seq == f.seq)
686
-        {
687
-            if (mDebug)
688
-            {
689
-                printf("Client: Recieved ack %u\n", f.seq);
690
-            }
691
-
692
-            ++seq;
693
-        }
694
-    }
695
-
696
-    mKillServer = false;
697
-}
698
-

+ 2
- 187
src/OpenRaider.cpp Просмотреть файл

@@ -31,10 +31,6 @@ std::map<int, int> gMapTex2Bump;
31 31
 Vector <unsigned int> gColorTextureHACK;
32 32
 int gTextureOffset;
33 33
 entity_t *LARA = 0x0;
34
-entity_t *gClientPlayer[32];
35
-unsigned int gNetTicks = 0;
36
-unsigned int gNetLastTicks = 0;
37
-bool gStartServer = false;
38 34
 skeletal_model_t *gLaraModel = 0x0;
39 35
 char *gFontFilename = 0x0;
40 36
 
@@ -58,8 +54,6 @@ OpenRaider *OpenRaider::Instance()
58 54
 
59 55
 
60 56
 void killOpenRaiderSingleton() {
61
-    killNetworkSingleton();
62
-
63 57
     printf("Shutting down Game...\n");
64 58
 
65 59
     // Requires public deconstructor
@@ -75,13 +69,6 @@ void killOpenRaiderSingleton() {
75 69
 
76 70
 OpenRaider::OpenRaider() : SDLSystem()
77 71
 {
78
-    Network::Instance();
79
-
80
-    for (unsigned int i = 0; i < 32; ++i)
81
-    {
82
-        gClientPlayer[i] = 0x0;
83
-    }
84
-
85 72
     m_pakDir = 0x0;
86 73
     m_audioDir = 0x0;
87 74
     m_homeDir = 0x0;
@@ -100,7 +87,6 @@ OpenRaider::OpenRaider() : SDLSystem()
100 87
      * Only do this when you know the amount of commands + 1 (0 reserved)
101 88
      */
102 89
     mMode[addCommandMode("[OpenRaider.Engine]")] = 2;
103
-    mMode[addCommandMode("[Network.Server]")] = 5;
104 90
     mMode[addCommandMode("[Video.OpenGL]")] = 0;
105 91
     mMode[addCommandMode("[Audio.OpenAL]")] = 1;
106 92
     mMode[addCommandMode("[OpenRaider.Console]")] = 4;
@@ -194,116 +180,6 @@ void openraider_error(const char *func_name, const char *error,
194 180
 }
195 181
 
196 182
 
197
-void from_network_layer(network_packet_t *p, unsigned int *last_id)
198
-{
199
-    static unsigned int i = 0;
200
-
201
-
202
-    *last_id = i++;
203
-
204
-    if (gNetTicks > gNetLastTicks + 200) // 200ms
205
-    {
206
-        gNetLastTicks = gNetTicks;
207
-        p->send = 1;
208
-    }
209
-
210
-    if (LARA)
211
-    {
212
-        p->pos[0] = LARA->pos[0];
213
-        p->pos[1] = LARA->pos[1];
214
-        p->pos[2] = LARA->pos[2];
215
-        p->yaw = LARA->angles[1];
216
-        p->pitch = LARA->angles[1];
217
-        p->view_model = LARA->modelId;
218
-
219
-        SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
220
-
221
-        if (mdl)
222
-        {
223
-            p->aframe = mdl->getAnimation();
224
-            p->bframe = mdl->getFrame();
225
-        }
226
-    }
227
-
228
-#ifdef DEBUG_NETWORK
229
-    printf("<> Sending data\n");
230
-#endif
231
-}
232
-
233
-
234
-void to_network_layer(network_packet_t p)
235
-{
236
-    OpenRaider &game = *OpenRaider::Instance();
237
-
238
-
239
-#ifdef DEBUG_NETWORK
240
-    printf("<> Recieved data\n");
241
-#endif
242
-
243
-    if (gClientPlayer[p.cid])
244
-    {
245
-        gClientPlayer[p.cid]->pos[0] = p.pos[0];
246
-        gClientPlayer[p.cid]->pos[1] = p.pos[1];
247
-        gClientPlayer[p.cid]->pos[2] = p.pos[2];
248
-        gClientPlayer[p.cid]->angles[1] = p.yaw;
249
-        gClientPlayer[p.cid]->angles[2] = p.pitch;
250
-    }
251
-    else if (LARA)
252
-    {
253
-        gClientPlayer[p.cid] = new entity_t;
254
-
255
-        gClientPlayer[p.cid]->pos[0] = p.pos[0];
256
-        gClientPlayer[p.cid]->pos[1] = p.pos[1];
257
-        gClientPlayer[p.cid]->pos[2] = p.pos[2];
258
-        gClientPlayer[p.cid]->angles[1] = p.yaw;
259
-        gClientPlayer[p.cid]->angles[2] = p.pitch;
260
-        gClientPlayer[p.cid]->moving = true;
261
-        gClientPlayer[p.cid]->objectId = 0;
262
-        gClientPlayer[p.cid]->id = LARA->id+1000+p.cid;
263
-        gClientPlayer[p.cid]->type = 0x02;
264
-
265
-        SkeletalModel *mdl = new SkeletalModel();
266
-        gClientPlayer[p.cid]->tmpHook = mdl;
267
-        mdl->setAnimation(p.aframe);
268
-        mdl->setFrame(p.bframe);
269
-        mdl->setIdleAnimation(TR_ANIAMTION_STAND);
270
-        gClientPlayer[p.cid]->modelId = LARA->modelId; //p.view_model;
271
-        gClientPlayer[p.cid]->animate = true;
272
-
273
-        gWorld.addEntity(gClientPlayer[p.cid]);
274
-        game.print(true, "A new player (%u) connected", p.cid);
275
-    }
276
-
277
-    if (LARA)
278
-    {
279
-        Network &network = *Network::Instance();
280
-        network_frame_t &gPiggyBack = network.getPiggyBack();
281
-
282
-
283
-        if (gNetTicks > gNetLastTicks + 200)
284
-        {
285
-            gNetLastTicks = gNetTicks;
286
-            gPiggyBack.data.send = 1;
287
-        }
288
-
289
-        gPiggyBack.data.pos[0] = LARA->pos[0];
290
-        gPiggyBack.data.pos[1] = LARA->pos[1];
291
-        gPiggyBack.data.pos[2] = LARA->pos[2];
292
-        gPiggyBack.data.yaw = LARA->angles[1];
293
-        gPiggyBack.data.pitch = LARA->angles[2];
294
-        gPiggyBack.data.view_model = LARA->modelId;
295
-
296
-        SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
297
-
298
-        if (mdl)
299
-        {
300
-            gPiggyBack.data.aframe = mdl->getAnimation();
301
-            gPiggyBack.data.bframe = mdl->getFrame();
302
-        }
303
-    }
304
-}
305
-
306
-
307 183
 void OpenRaider::handleMouseMotionEvent(float x, float y)
308 184
 {
309 185
     if (x > 0)
@@ -1165,8 +1041,8 @@ void OpenRaider::gameFrame()
1165 1041
 
1166 1042
 
1167 1043
     // Remember: ticks in milliseconds, time in hundredths
1168
-    gNetTicks = ticks = systemTimerGet();
1169
-    time = gNetTicks * 0.1f;
1044
+    ticks = systemTimerGet();
1045
+    time = ticks * 0.1f;
1170 1046
 
1171 1047
     switch (m_render.getMode())
1172 1048
     {
@@ -2835,45 +2711,6 @@ void OpenRaider::consoleCommand(char *cmd)
2835 2711
     {
2836 2712
         shutdown(0);
2837 2713
     }
2838
-    else if (rc_command("port", cmd))
2839
-    {
2840
-        Network &net = *Network::Instance();
2841
-        net.setPort(atoi(cmd));
2842
-    }
2843
-    else if (rc_command("killserver", cmd))
2844
-    {
2845
-        Network &net = *Network::Instance();
2846
-
2847
-
2848
-        print(true, "Stopping network server...");
2849
-        net.killServerThread();
2850
-    }
2851
-    else if (rc_command("server", cmd))
2852
-    {
2853
-        Network &net = *Network::Instance();
2854
-
2855
-
2856
-        print(true, "Starting network server...");
2857
-        net.spawnServerThread();
2858
-    }
2859
-    else if (rc_command("disconnect", cmd))
2860
-    {
2861
-        Network &net = *Network::Instance();
2862
-
2863
-
2864
-        print(true, "Diconnecting...");
2865
-        net.killClientThread();
2866
-    }
2867
-    else if (rc_command("connect", cmd))
2868
-    {
2869
-        Network &net = *Network::Instance();
2870
-
2871
-
2872
-        print(true, "Connecting to %s...", cmd);
2873
-
2874
-        net.setRemoteHost(cmd);
2875
-        net.spawnClientThread();
2876
-    }
2877 2714
     else if (rc_command("fly", cmd))
2878 2715
     {
2879 2716
         if (LARA)
@@ -3549,28 +3386,6 @@ void OpenRaider::handleCommand(char *cmd, unsigned int mode)
3549 3386
 
3550 3387
             consoleCommand(cmd);
3551 3388
             break;
3552
-        case 5:
3553
-            if (rc_command("Enable", cmd))
3554
-            {
3555
-                rc_get_bool(cmd, &gStartServer);
3556
-            }
3557
-            else if (rc_command("Port", cmd))
3558
-            {
3559
-                if (gStartServer)
3560
-                {
3561
-                    Network &net = *Network::Instance();
3562
-                    int port = atoi(cmd);
3563
-
3564
-                    net.setPort(port);
3565
-                    print(true, "Starting network server on port %i...", port);
3566
-                    net.spawnServerThread();
3567
-                }
3568
-            }
3569
-            else
3570
-            {
3571
-                printf("Command> [Network.Server] '%s' not implemented\n", cmd);
3572
-            }
3573
-            break;
3574 3389
     }
3575 3390
 }
3576 3391
 

+ 1
- 14
test/CMakeLists.txt Просмотреть файл

@@ -37,19 +37,6 @@ target_link_libraries (SoundTest ${SOUNDLIBS})
37 37
 
38 38
 #################################################################
39 39
 
40
-# Add Thread Library
41
-find_package (Threads REQUIRED)
42
-set (THREADLIBS ${THREADLIBS} ${CMAKE_THREAD_LIBS_INIT})
43
-
44
-# Network Test
45
-set (NETWORKSRCS "${PROJECT_SOURCE_DIR}/test/Network.cpp" "${PROJECT_SOURCE_DIR}/src/Network.cpp")
46
-set (NETWORKSRCS ${NETWORKSRCS} "${PROJECT_SOURCE_DIR}/src/utils/math.cpp" "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp")
47
-add_executable (NetworkTest EXCLUDE_FROM_ALL ${NETWORKSRCS})
48
-set_target_properties (NetworkTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
49
-target_link_libraries (NetworkTest m ${THREADLIBS})
50
-
51
-#################################################################
52
-
53 40
 # Math Test
54 41
 set (MATHSRCS "${PROJECT_SOURCE_DIR}/test/math.cpp" "${PROJECT_SOURCE_DIR}/src/utils/math.cpp" "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp")
55 42
 add_executable (MathTest EXCLUDE_FROM_ALL ${MATHSRCS})
@@ -108,7 +95,7 @@ target_link_libraries (TombRaiderTest ${ZLIBS})
108 95
 
109 96
 # Add test build target
110 97
 add_custom_target (tests)
111
-add_dependencies (tests GLStringTest MathTest MatrixTest NetworkTest SoundTest TGATest TombRaiderTest)
98
+add_dependencies (tests GLStringTest MathTest MatrixTest SoundTest TGATest TombRaiderTest)
112 99
 
113 100
 # Add test run target
114 101
 add_custom_target (testRun echo "Running Unit Tests..."

+ 0
- 96
test/Network.cpp Просмотреть файл

@@ -1,96 +0,0 @@
1
-/*!
2
- * \file test/Network.cpp
3
- * \brief Networking Singleton Unit test
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <Network.h>
9
-
10
-#include <stdlib.h>
11
-#include <stdio.h>
12
-#include <unistd.h>
13
-
14
-extern network_frame_t gPiggyBack;
15
-
16
-void from_network_layer(network_packet_t *p, unsigned int *last_id)
17
-{
18
-    static unsigned int i = 0;
19
-
20
-
21
-    if (!p)
22
-    {
23
-        return;
24
-    }
25
-
26
-    *last_id = i++;
27
-
28
-    sleep(1);
29
-
30
-    p->send = 1;
31
-    p->pos[0] = i*3;
32
-    p->pos[1] = i*3+1;
33
-    p->pos[2] = i*3+2;
34
-
35
-    printf("<S>ending { %f %f %f }\n", p->pos[0], p->pos[1], p->pos[2]);
36
-}
37
-
38
-
39
-void to_network_layer(network_packet_t p)
40
-{
41
-    printf("<R>ecieved { %f %f %f }\n", p.pos[0], p.pos[1], p.pos[2]);
42
-
43
-    gPiggyBack.data.pos[0] = gPiggyBack.seq*4;
44
-    gPiggyBack.data.pos[1] = gPiggyBack.seq*4+1;
45
-    gPiggyBack.data.pos[2] = gPiggyBack.seq*4+2;
46
-    gPiggyBack.data.send = 1;
47
-    gPiggyBack.data.yaw = 90.0f;
48
-}
49
-
50
-
51
-int main(int argc, char *argv[])
52
-{
53
-    printf("\n\n[Network class test]\n");
54
-    Network &test = *Network::Instance();
55
-
56
-
57
-    if (argc > 3)
58
-    {
59
-        if (argv[1][1] == 'v')
60
-        {
61
-            test.setDebug(true);
62
-        }
63
-
64
-        switch (argv[1][0])
65
-        {
66
-            case 'c':
67
-                test.setRemoteHost(argv[2]);
68
-                test.setPort(atoi(argv[3]));
69
-                test.runClient();
70
-                break;
71
-            case 's':
72
-                test.setBindHost(argv[2]);
73
-                test.setPort(atoi(argv[3]));
74
-                test.runServer();
75
-                break;
76
-            default:
77
-                printf("Error in command line, run %s for help\n", argv[0]);
78
-        }
79
-    }
80
-    else if (argc > 2)
81
-    {
82
-        test.setPort(atoi(argv[2]));
83
-        test.runServer();
84
-    }
85
-    else
86
-    {
87
-        printf("Server: %s s [bind_host_name] port\n", argv[0]);
88
-        printf("Client: %s c remote_host_name remote_host_port\n", argv[0]);
89
-        printf("Append 'v' behind c/s option for verbose. eg cv\n");
90
-    }
91
-
92
-    killNetworkSingleton();
93
-
94
-    return 0;
95
-}
96
-

Загрузка…
Отмена
Сохранить