cocoaTouch/gameSetup.m
author koda
Tue, 12 Jan 2010 07:32:15 +0000
changeset 2692 ce9992075118
parent 2691 c0da3a98c01c
permissions -rw-r--r--
better network support + initial work for returning to frontend
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     1
//
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     2
//  gameSetup.m
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     3
//  hwengine
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     4
//
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     5
//  Created by Vittorio on 10/01/10.
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     7
//
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     8
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
     9
#import <pthread.h>
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    11
#import "gameSetup.h"
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    12
#import "SDL_net.h"
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    13
#import "PascalImports.h"
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    14
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    15
#define IPC_PORT 51342
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    16
#define IPC_PORT_STR "51342"
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    17
#define BUFFER_SIZE 256
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    18
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    19
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    20
//
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    21
TCPsocket sd, csd; /* Socket descriptor, Client socket descriptor */
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    22
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    23
@implementation gameSetup
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    24
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    25
int sendToEngine(NSString *string) {
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    26
	Uint8 length = [string length];
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    27
	
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    28
	SDLNet_TCP_Send(csd, &length , 1);
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    29
	return SDLNet_TCP_Send(csd, [string UTF8String], length);
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    30
}
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    31
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    32
void engineProtocolThread () {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    33
	IPaddress ip;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    34
	int idx, eProto;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    35
	BOOL serverQuit, clientQuit;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    36
	char buffer[BUFFER_SIZE], string[BUFFER_SIZE];
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    37
	Uint8 msgSize;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    38
	Uint16 gameTicks;
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    39
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    40
	
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    41
	if (SDLNet_Init() < 0) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    42
		fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    43
		exit(EXIT_FAILURE);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    44
	}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    45
	
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    46
	/* Resolving the host using NULL make network interface to listen */
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    47
	if (SDLNet_ResolveHost(&ip, NULL, IPC_PORT) < 0) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    48
		fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    49
		exit(EXIT_FAILURE);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    50
	}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    51
	
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    52
	/* Open a connection with the IP provided (listen on the host's port) */
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    53
	if (!(sd = SDLNet_TCP_Open(&ip))) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    54
		fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    55
		exit(EXIT_FAILURE);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    56
	}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    57
	
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    58
	NSLog(@"engineProtocolThread - Waiting for a client");
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    59
	
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    60
	serverQuit = NO;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    61
	while (!serverQuit) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    62
		
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    63
		/* This check the sd if there is a pending connection.
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    64
		 * If there is one, accept that, and open a new socket for communicating */
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    65
		if ((csd = SDLNet_TCP_Accept(sd))) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    66
			
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    67
			NSLog(@"engineProtocolThread - Client found");
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    68
			
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    69
			//first byte of the command alwayas contain the size of the command
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    70
			SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8));
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    71
			
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    72
			SDLNet_TCP_Recv(csd, buffer, msgSize);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    73
			gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    74
			NSLog(@"engineProtocolThread - %d: received [%s]", gameTicks, buffer);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    75
			
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    76
			if ('C' == buffer[0]) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
    77
				NSLog(@"engineProtocolThread - Client found and connected");
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    78
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    79
				// send config data data
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    80
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    81
				// local game
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    82
				sendToEngine(@"TL");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    83
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    84
				// seed info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    85
				sendToEngine(@"eseed {232c1b42-7d39-4ee6-adf8-4240e1f1efb8}");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    86
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    87
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    88
				sendToEngine(@"e$gmflags 256"); 
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    89
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    90
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    91
				sendToEngine(@"e$damagepct 100");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    92
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    93
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    94
				sendToEngine(@"e$turntime 45000");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    95
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    96
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    97
				sendToEngine(@"e$minestime 3000");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    98
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
    99
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   100
				sendToEngine(@"e$landadds 4");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   101
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   102
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   103
				sendToEngine(@"e$sd_turns 15");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   104
												
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   105
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   106
				sendToEngine(@"e$casefreq 5");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   107
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   108
				// various flags
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   109
				sendToEngine(@"e$template_filter 1");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   110
								
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   111
				// theme info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   112
				sendToEngine(@"etheme Freeway");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   113
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   114
				// team 1 info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   115
				sendToEngine(@"eaddteam 4421353 System Cats");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   116
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   117
				// team 1 grave info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   118
				sendToEngine(@"egrave star");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   119
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   120
				// team 1 fort info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   121
				sendToEngine(@"efort  Earth");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   122
								
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   123
				// team 1 voicepack info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   124
				sendToEngine(@"evoicepack Classic");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   125
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   126
				// team 1 binds (skipped)				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   127
				// team 1 members info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   128
				//for (int i=0; i<4; i++) {
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   129
					sendToEngine(@"eaddhh 0 100 Snow Leopard");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   130
					sendToEngine(@"ehat NoHat");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   131
				//}
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   132
				// team 1 ammostore
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   133
				sendToEngine(@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   134
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   135
				// team 2 info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   136
				sendToEngine(@"eaddteam 4100897 Poke-MAN");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   137
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   138
				// team 2 grave info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   139
				sendToEngine(@"egrave Badger");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   140
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   141
				// team 2 fort info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   142
				sendToEngine(@"efort UFO");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   143
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   144
				// team 2 voicepack info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   145
				sendToEngine(@"evoicepack Classic");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   146
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   147
				// team 2 binds (skipped)
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   148
				// team 2 members info
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   149
			//	for (int i=0; i<4; i++) {
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   150
					sendToEngine(@"eaddhh 0 100 Raichu");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   151
					sendToEngine(@"ehat Bunny");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   152
			//	}
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   153
				
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   154
				// team 2 ammostore
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   155
				sendToEngine(@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144");
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   156
				
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   157
				clientQuit = NO;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   158
			} else {
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   159
				NSLog(@"engineProtocolThread - wrong message, closing connection");
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   160
				clientQuit = YES;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   161
			}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   162
			
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   163
			while (!clientQuit){
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   164
				/* Now we can communicate with the client using csd socket
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   165
				 * sd will remain opened waiting other connections */
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   166
				idx = 0;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   167
				msgSize = 0;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   168
				memset(buffer, 0, BUFFER_SIZE);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   169
				memset(string, 0, BUFFER_SIZE);
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   170
				if (SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8)) <= 0)
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   171
					clientQuit = YES;
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   172
				if (SDLNet_TCP_Recv(csd, buffer, msgSize) <=0)
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   173
					clientQuit = YES;
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   174
				
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   175
				gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   176
				//NSLog(@"engineProtocolThread - %d: received [%s]", gameTicks, buffer);
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   177
				
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   178
				switch (buffer[0]) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   179
					case '?':
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   180
						NSLog(@"Ping? Pong!");
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   181
						sendToEngine(@"!");
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   182
						break;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   183
					case 'E':
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   184
						NSLog(@"ERROR - last console line: [%s]", buffer);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   185
						clientQuit = YES;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   186
						break;
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   187
					case 'e':
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   188
						sscanf(buffer, "%*s %d", &eProto);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   189
						if (HW_protoVer() == eProto) {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   190
							NSLog(@"Setting protocol version %s", buffer);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   191
						} else {
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   192
							NSLog(@"ERROR - wrong protocol number: [%s] - expecting %d", buffer, eProto);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   193
							clientQuit = YES;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   194
						}
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   195
						break;
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   196
					default:
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   197
						// empty packet or just statistics
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   198
						break;
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   199
					case 'i':
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   200
						switch (buffer[1]) {
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   201
							case 'r':
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   202
								NSLog(@"Winning team: %s", &buffer[2]);
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   203
								break;
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   204
							case 'k':
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   205
								NSLog(@"Best Hedgehog: %s", &buffer[2]);
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   206
								break;
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   207
						}
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   208
						break;
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   209
					// missing case for exiting
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   210
				} 
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   211
				
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   212
				/*
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   213
				 // Terminate this connection 
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   214
				 if(strcmp(buffer, "exit") == 0)	{
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   215
				 quit2 = 1;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   216
				 printf("Terminate connection\n");
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   217
				 }
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   218
				 // Quit the thread
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   219
				 if(strcmp(buffer, "quit") == 0)	{
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   220
				 quit2 = 1;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   221
				 quit = 1;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   222
				 printf("Quit program\n");
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   223
				 }
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   224
				 */
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   225
			}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   226
		}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   227
		
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   228
		/* Close the client socket */
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   229
		SDLNet_TCP_Close(csd);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   230
	}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   231
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   232
	SDLNet_TCP_Close(sd);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   233
	SDLNet_Quit();
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   234
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   235
	[pool release];
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   236
	pthread_exit(NULL);
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   237
}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   238
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   239
void setupArgsForLocalPlay() {
2692
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   240
	memset(forward_argv, 0, forward_argc);
ce9992075118 better network support + initial work for returning to frontend
koda
parents: 2691
diff changeset
   241
	
2691
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   242
	forward_argc = 18;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   243
	forward_argv = (char **)realloc(forward_argv, forward_argc * sizeof(char *));
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   244
	//forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   245
	forward_argv[ 1] = forward_argv[0];	// (UNUSED)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   246
	forward_argv[ 2] = "320";			// cScreenWidth (NO EFFECT)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   247
	forward_argv[ 3] = "480";			// cScreenHeight (NO EFFECT)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   248
	forward_argv[ 4] = "32";			// cBitsStr
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   249
	forward_argv[ 5] = IPC_PORT_STR;	// ipcPort; <- (MAIN TODO)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   250
	forward_argv[ 6] = "1";				// cFullScreen (NO EFFECT)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   251
	forward_argv[ 7] = "0";				// isSoundEnabled (TOSET)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   252
	forward_argv[ 8] = "1";				// cVSyncInUse (UNUSED)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   253
	forward_argv[ 9] = "en.txt";		// cLocaleFName (TOSET)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   254
	forward_argv[10] = "100";			// cInitVolume (TOSET)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   255
	forward_argv[11] = "8";				// cTimerInterval
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   256
	forward_argv[12] = "Data";			// PathPrefix
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   257
	forward_argv[13] = "1";				// cShowFPS (TOSET?)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   258
	forward_argv[14] = "0";				// cAltDamage (TOSET)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   259
	forward_argv[15] = "Koda";			// UserNick (DecodeBase64(ParamStr(15)) FTW) <- TODO
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   260
	forward_argv[16] = "0";				// isMusicEnabled (TOSET)
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   261
	forward_argv[17] = "0";				// cReducedQuality
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   262
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   263
	return;
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   264
}
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   265
c0da3a98c01c initial support for engine protocol
koda
parents:
diff changeset
   266
@end