GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
authorkoda
Wed, 13 Jan 2010 09:41:35 +0000
changeset 2693 3207e0eacd43
parent 2692 ce9992075118
child 2694 dcd248e04f3d
GameSetup is now a class, use of NSThread instead of pthreads, game doesn't quit after first execution (but crashes aftewards - the irony)
cocoaTouch/GameSetup.h
cocoaTouch/GameSetup.m
cocoaTouch/MainWindow.xib
cocoaTouch/SDLOverrides/SDL_uikitappdelegate.h
cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m
cocoaTouch/gameSetup.h
cocoaTouch/gameSetup.m
hedgewars/uLocale.pas
hedgewars/uMisc.pas
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cocoaTouch/GameSetup.h	Wed Jan 13 09:41:35 2010 +0000
@@ -0,0 +1,26 @@
+//
+//  gameSetup.h
+//  hwengine
+//
+//  Created by Vittorio on 10/01/10.
+//  Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface GameSetup : NSObject {
+	NSLocale *locale;
+	BOOL engineProtocolStarted;
+}
+
+
+@property (nonatomic, retain) NSLocale *locale;
+@property (nonatomic) BOOL engineProtocolStarted;
+
+-(void) setArgsForLocalPlay;
+-(void) engineProtocol;
+-(void) startThread: (NSString *)selector;
+
+@end
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cocoaTouch/GameSetup.m	Wed Jan 13 09:41:35 2010 +0000
@@ -0,0 +1,279 @@
+//
+//  gameSetup.m
+//  hwengine
+//
+//  Created by Vittorio on 10/01/10.
+//  Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "GameSetup.h"
+#import "SDL_uikitappdelegate.h"
+#import "SDL_net.h"
+#import "PascalImports.h"
+
+#define IPC_PORT 51342
+#define IPC_PORT_STR "51342"
+#define BUFFER_SIZE 256
+
+
+// they should go in the interface
+TCPsocket sd, csd; /* Socket descriptor, Client socket descriptor */
+int sendToEngine (NSString * string) {
+	Uint8 length = [string length];
+	
+	SDLNet_TCP_Send(csd, &length , 1);
+	return SDLNet_TCP_Send(csd, [string UTF8String], length);
+}
+
+
+@implementation GameSetup
+
+@synthesize locale, engineProtocolStarted;
+
+-(id) init {
+	self = [super init];
+	self.locale = [NSLocale currentLocale];
+	self.engineProtocolStarted = NO;
+	return self;
+}
+
+-(void) startThread: (NSString *) selector {
+	SEL usage = NSSelectorFromString(selector);
+	
+	// do not start the server thread because the port is already bound
+	if (NO == engineProtocolStarted) {
+		engineProtocolStarted = YES;
+		[NSThread detachNewThreadSelector:usage toTarget:self withObject:nil];
+	}
+}
+
+-(void) engineProtocol {
+	IPaddress ip;
+	int idx, eProto;
+	BOOL serverQuit, clientQuit;
+	char buffer[BUFFER_SIZE], string[BUFFER_SIZE];
+	Uint8 msgSize;
+	Uint16 gameTicks;
+	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+	
+	if (SDLNet_Init() < 0) {
+		fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
+		exit(EXIT_FAILURE);
+	}
+	
+	/* Resolving the host using NULL make network interface to listen */
+	if (SDLNet_ResolveHost(&ip, NULL, IPC_PORT) < 0) {
+		fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
+		exit(EXIT_FAILURE);
+	}
+	
+	/* Open a connection with the IP provided (listen on the host's port) */
+	if (!(sd = SDLNet_TCP_Open(&ip))) {
+		fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
+		exit(EXIT_FAILURE);
+	}
+	
+	NSLog(@"engineProtocol - Waiting for a client");
+	
+	serverQuit = NO;
+	while (!serverQuit) {
+		
+		/* This check the sd if there is a pending connection.
+		 * If there is one, accept that, and open a new socket for communicating */
+		if ((csd = SDLNet_TCP_Accept(sd))) {
+			
+			NSLog(@"engineProtocol - Client found");
+			
+			//first byte of the command alwayas contain the size of the command
+			SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8));
+			
+			SDLNet_TCP_Recv(csd, buffer, msgSize);
+			gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
+			//NSLog(@"engineProtocol - %d: received [%s]", gameTicks, buffer);
+			
+			if ('C' == buffer[0]) {
+				NSLog(@"engineProtocol - sending game config");
+				
+				// send config data data
+				
+				// local game
+				sendToEngine(@"TL");
+				
+				// seed info
+				sendToEngine(@"eseed {232c1b42-7d39-4ee6-adf8-4240e1f1efb8}");
+				
+				// various flags
+				sendToEngine(@"e$gmflags 256"); 
+
+				// various flags
+				sendToEngine(@"e$damagepct 100");
+				
+				// various flags
+				sendToEngine(@"e$turntime 45000");
+				
+				// various flags
+				sendToEngine(@"e$minestime 3000");
+				
+				// various flags
+				sendToEngine(@"e$landadds 4");
+				
+				// various flags
+				sendToEngine(@"e$sd_turns 15");
+												
+				// various flags
+				sendToEngine(@"e$casefreq 5");
+				
+				// various flags
+				sendToEngine(@"e$template_filter 1");
+								
+				// theme info
+				sendToEngine(@"etheme Freeway");
+				
+				// team 1 info
+				sendToEngine(@"eaddteam 4421353 System Cats");
+				
+				// team 1 grave info
+				sendToEngine(@"egrave star");
+				
+				// team 1 fort info
+				sendToEngine(@"efort  Earth");
+								
+				// team 1 voicepack info
+				sendToEngine(@"evoicepack Classic");
+				
+				// team 1 binds (skipped)				
+				// team 1 members info
+				sendToEngine(@"eaddhh 0 100 Snow Leopard");
+				sendToEngine(@"ehat NoHat");
+				
+				// team 1 ammostore
+				sendToEngine(@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144");
+
+				// team 2 info
+				sendToEngine(@"eaddteam 4100897 Poke-MAN");
+				
+				// team 2 grave info
+				sendToEngine(@"egrave Badger");
+				
+				// team 2 fort info
+				sendToEngine(@"efort UFO");
+				
+				// team 2 voicepack info
+				sendToEngine(@"evoicepack Classic");
+				
+				// team 2 binds (skipped)
+				// team 2 members info
+				sendToEngine(@"eaddhh 0 100 Raichu");
+				sendToEngine(@"ehat Bunny");
+				
+				// team 2 ammostore
+				sendToEngine(@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144");
+				
+				clientQuit = NO;
+			} else {
+				NSLog(@"engineProtocolThread - wrong message, closing connection");
+				clientQuit = YES;
+			}
+			
+			while (!clientQuit){
+				/* Now we can communicate with the client using csd socket
+				 * sd will remain opened waiting other connections */
+				idx = 0;
+				msgSize = 0;
+				memset(buffer, 0, BUFFER_SIZE);
+				memset(string, 0, BUFFER_SIZE);
+				if (SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8)) <= 0)
+					clientQuit = YES;
+				if (SDLNet_TCP_Recv(csd, buffer, msgSize) <=0)
+					clientQuit = YES;
+				
+				gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
+				//NSLog(@"engineProtocolThread - %d: received [%s]", gameTicks, buffer);
+				
+				switch (buffer[0]) {
+					case '?':
+						NSLog(@"Ping? Pong!");
+						sendToEngine(@"!");
+						break;
+					case 'E':
+						NSLog(@"ERROR - last console line: [%s]", buffer);
+						clientQuit = YES;
+						break;
+					case 'e':
+						sscanf(buffer, "%*s %d", &eProto);
+						if (HW_protoVer() == eProto) {
+							NSLog(@"Setting protocol version %s", buffer);
+						} else {
+							NSLog(@"ERROR - wrong protocol number: [%s] - expecting %d", buffer, eProto);
+							clientQuit = YES;
+						}
+						break;
+					case 'i':
+						switch (buffer[1]) {
+							case 'r':
+								NSLog(@"Winning team: %s", &buffer[2]);
+								break;
+							case 'k':
+								NSLog(@"Best Hedgehog: %s", &buffer[2]);
+								break;
+						}
+						break;
+					default:
+						// empty packet or just statistics
+						break;
+					// missing case for exiting right away
+				} 
+			}
+		}
+		
+		/* Close the client socket */
+		SDLNet_TCP_Close(csd);
+	}
+
+	SDLNet_TCP_Close(sd);
+	SDLNet_Quit();
+
+	[pool release];
+	[NSThread exit];
+}
+
+-(void) setArgsForLocalPlay {
+	NSString *localeString = [[self.locale localeIdentifier] stringByAppendingString:@".txt"];
+	NSLog(localeString);
+	
+	memset(forward_argv, 0, forward_argc);
+	
+	forward_argc = 18;
+	forward_argv = (char **)realloc(forward_argv, forward_argc * sizeof(char *));
+	//forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
+	forward_argv[ 1] = forward_argv[0];	// (UNUSED)
+	forward_argv[ 2] = "320";			// cScreenWidth (NO EFFECT)
+	forward_argv[ 3] = "480";			// cScreenHeight (NO EFFECT)
+	forward_argv[ 4] = "32";			// cBitsStr
+	forward_argv[ 5] = IPC_PORT_STR;	// ipcPort;
+	forward_argv[ 6] = "1";				// cFullScreen (NO EFFECT)
+	forward_argv[ 7] = "0";				// isSoundEnabled (TOSET)
+	forward_argv[ 8] = "1";				// cVSyncInUse (UNUSED)
+	forward_argv[ 9] = [localeString UTF8String];		// cLocaleFName
+	forward_argv[10] = "100";			// cInitVolume (TOSET)
+	forward_argv[11] = "8";				// cTimerInterval
+	forward_argv[12] = "Data";			// PathPrefix
+	forward_argv[13] = "1";				// cShowFPS (TOSET?)
+	forward_argv[14] = "0";				// cAltDamage (TOSET)
+	forward_argv[15] = "Koda";			// UserNick (DecodeBase64(ParamStr(15)) FTW) <- TODO
+	forward_argv[16] = "0";				// isMusicEnabled (TOSET)
+	forward_argv[17] = "0";				// cReducedQuality
+
+fprintf(stderr, forward_argv[9]);
+	return;
+}
+
+
+/*
+ -(void) dealloc {
+	[super dealloc];
+}
+ */
+
+
+@end
--- a/cocoaTouch/MainWindow.xib	Tue Jan 12 07:32:15 2010 +0000
+++ b/cocoaTouch/MainWindow.xib	Wed Jan 13 09:41:35 2010 +0000
@@ -43,7 +43,7 @@
 				<string key="NSFrameSize">{320, 480}</string>
 				<object class="NSColor" key="IBUIBackgroundColor">
 					<int key="NSColorSpace">1</int>
-					<bytes key="NSRGB">MSAxIDEAA</bytes>
+					<bytes key="NSRGB">MCAwIDAAA</bytes>
 				</object>
 				<bool key="IBUIOpaque">NO</bool>
 				<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
@@ -392,7 +392,7 @@
 					</object>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
 						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">../../../hedge.build/trunk/cocoaTouch/SDL_uikitappdelegate.h</string>
+						<string key="minorKey">../../../hedge.build/trunk/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.h</string>
 					</object>
 				</object>
 				<object class="IBPartialClassDescription">
--- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.h	Tue Jan 12 07:32:15 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.h	Wed Jan 13 09:41:35 2010 +0000
@@ -23,19 +23,24 @@
 #import <UIKit/UIKit.h>
 #import "SDL_video.h"
 
+@class GameSetup;
+
 @interface SDLUIKitDelegate:NSObject<UIApplicationDelegate> {
     UIWindow *window;
 	SDL_WindowID windowID;
 	UITabBarController *controller;
+	GameSetup *setup;
 }
 
 // the outlets are set in MainWindow.xib
 @property (readwrite, retain) IBOutlet UIWindow *window;
 @property (readwrite, assign) SDL_WindowID windowID;
 @property (nonatomic, retain) IBOutlet UITabBarController *controller;
+@property (nonatomic, retain) GameSetup *setup;
 
 +(SDLUIKitDelegate *)sharedAppDelegate;
 -(void) startSDLgame;
++(void) resetFrontend;
 
 int forward_argc;
 char **forward_argv;
--- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Tue Jan 12 07:32:15 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Wed Jan 13 09:41:35 2010 +0000
@@ -26,7 +26,7 @@
 #import "SDL_events_c.h"
 #import "jumphack.h"
 #import "SDL_video.h"
-#import "gameSetup.h"
+#import "GameSetup.h"
 
 #ifdef main
 #undef main
@@ -55,7 +55,7 @@
 
 @implementation SDLUIKitDelegate
 
-@synthesize window, windowID, controller;
+@synthesize window, windowID, controller, setup;
 
 /* convenience method */
 +(SDLUIKitDelegate *)sharedAppDelegate {
@@ -63,25 +63,21 @@
 	return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
 }
 
-void preSDL_main(){
+-(void) launchSDL_main{
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
+	
+	// must setup arguments in the same thread
+	[setup setArgsForLocalPlay];
+	
+	// run the user's application, passing argc and argv
 	SDL_main(forward_argc, forward_argv);
 
 	[pool release];
 }
 
-- (void) startSDLgame {
-	pthread_t threadID;
-
-	if (NO == isServerRunning) {
-		// don't start another server because the port is already bound
-		pthread_create (&threadID, NULL, (void *) (*engineProtocolThread), NULL);
-		pthread_detach (threadID);
-		isServerRunning = YES;
-	}
-
-	setupArgsForLocalPlay();
+-(IBAction) startSDLgame {
+	
+	[setup startThread:@"engineProtocol"];
 	
 	// remove the current view to free resources
 	[UIView beginAnimations:nil context:NULL];
@@ -91,24 +87,20 @@
 	[controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5];
 	//[controller.view removeFromSuperview];
 	
-	/* run the user's application, passing argc and argv */
 	NSLog(@"Game is launching...");
-	/*pthread_create (&threadID, NULL, (void *) (*preSDL_main), NULL);
-	pthread_detach (threadID);*/
-	int res = SDL_main(forward_argc, forward_argv);
 
-	// can't reach here yet
-	NSLog(@"Game exited with status %d", res);
+	[NSThread detachNewThreadSelector:@selector(launchSDL_main) toTarget:self withObject:nil];
+	
+	//SDL_main(forward_argc, forward_argv);
 
-	//[self performSelector:@selector(makeNewView) withObject:nil afterDelay:0.0];
-	/* exit, passing the return status from the user's application */
-	//exit(exit_status);
+
 }
 
 // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib)
 -(void) applicationDidFinishLaunching:(UIApplication *)application {
 	[application setStatusBarHidden:YES animated:NO];
 
+	setup = [[GameSetup alloc] init]; 
 	/* Set working directory to resource path */
 	[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
 //#import "SoundEffect.h"	
@@ -149,22 +141,32 @@
 	return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
 }
 */
++(void) resetFrontend {
+	[[[SDLUIKitDelegate sharedAppDelegate].window viewWithTag:54867] removeFromSuperview];
+	[[SDLUIKitDelegate sharedAppDelegate].window addSubview:[SDLUIKitDelegate sharedAppDelegate].controller.view];
+	
+	[UIView beginAnimations:nil context:NULL];
+	[UIView setAnimationDuration:1];
+	[SDLUIKitDelegate sharedAppDelegate].controller.view.alpha = 1;
+	[UIView commitAnimations];
+	
+	[[SDLUIKitDelegate sharedAppDelegate].window makeKeyAndVisible];
+}
+
 
 void IPH_returnFrontend (void) {
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-	
-	[[[SDLUIKitDelegate sharedAppDelegate].window viewWithTag:54867] removeFromSuperview];
-	[[SDLUIKitDelegate sharedAppDelegate].window addSubview:[SDLUIKitDelegate sharedAppDelegate].controller.view];
-//	[[SDLUIKitDelegate sharedAppDelegate].window makeKeyAndVisible];
+
+	[SDLUIKitDelegate resetFrontend];
 	NSLog(@"Game exited...");
-//	pthread_exit(NULL);
+
 	[pool release];
-	exit(0);
-//	while(1);	//prevent exiting	
+	[NSThread exit];
 }
 
 
 -(void) dealloc {
+	[setup release];
 	[controller release];
 	[window release];
 	[super dealloc];
--- a/cocoaTouch/gameSetup.h	Tue Jan 12 07:32:15 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-//
-//  gameSetup.h
-//  hwengine
-//
-//  Created by Vittorio on 10/01/10.
-//  Copyright 2010 __MyCompanyName__. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-
-@interface gameSetup : NSObject {
-
-}
-
-@end
-
-void engineProtocolThread ();
-void setupArgsForLocalPlay();
--- a/cocoaTouch/gameSetup.m	Tue Jan 12 07:32:15 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,266 +0,0 @@
-//
-//  gameSetup.m
-//  hwengine
-//
-//  Created by Vittorio on 10/01/10.
-//  Copyright 2010 __MyCompanyName__. All rights reserved.
-//
-
-#import <pthread.h>
-#import "SDL_uikitappdelegate.h"
-#import "gameSetup.h"
-#import "SDL_net.h"
-#import "PascalImports.h"
-
-#define IPC_PORT 51342
-#define IPC_PORT_STR "51342"
-#define BUFFER_SIZE 256
-
-
-//
-TCPsocket sd, csd; /* Socket descriptor, Client socket descriptor */
-
-@implementation gameSetup
-
-int sendToEngine(NSString *string) {
-	Uint8 length = [string length];
-	
-	SDLNet_TCP_Send(csd, &length , 1);
-	return SDLNet_TCP_Send(csd, [string UTF8String], length);
-}
-
-void engineProtocolThread () {
-	IPaddress ip;
-	int idx, eProto;
-	BOOL serverQuit, clientQuit;
-	char buffer[BUFFER_SIZE], string[BUFFER_SIZE];
-	Uint8 msgSize;
-	Uint16 gameTicks;
-	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-	
-	if (SDLNet_Init() < 0) {
-		fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
-		exit(EXIT_FAILURE);
-	}
-	
-	/* Resolving the host using NULL make network interface to listen */
-	if (SDLNet_ResolveHost(&ip, NULL, IPC_PORT) < 0) {
-		fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
-		exit(EXIT_FAILURE);
-	}
-	
-	/* Open a connection with the IP provided (listen on the host's port) */
-	if (!(sd = SDLNet_TCP_Open(&ip))) {
-		fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
-		exit(EXIT_FAILURE);
-	}
-	
-	NSLog(@"engineProtocolThread - Waiting for a client");
-	
-	serverQuit = NO;
-	while (!serverQuit) {
-		
-		/* This check the sd if there is a pending connection.
-		 * If there is one, accept that, and open a new socket for communicating */
-		if ((csd = SDLNet_TCP_Accept(sd))) {
-			
-			NSLog(@"engineProtocolThread - Client found");
-			
-			//first byte of the command alwayas contain the size of the command
-			SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8));
-			
-			SDLNet_TCP_Recv(csd, buffer, msgSize);
-			gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
-			NSLog(@"engineProtocolThread - %d: received [%s]", gameTicks, buffer);
-			
-			if ('C' == buffer[0]) {
-				NSLog(@"engineProtocolThread - Client found and connected");
-				
-				// send config data data
-				
-				// local game
-				sendToEngine(@"TL");
-				
-				// seed info
-				sendToEngine(@"eseed {232c1b42-7d39-4ee6-adf8-4240e1f1efb8}");
-				
-				// various flags
-				sendToEngine(@"e$gmflags 256"); 
-
-				// various flags
-				sendToEngine(@"e$damagepct 100");
-				
-				// various flags
-				sendToEngine(@"e$turntime 45000");
-				
-				// various flags
-				sendToEngine(@"e$minestime 3000");
-				
-				// various flags
-				sendToEngine(@"e$landadds 4");
-				
-				// various flags
-				sendToEngine(@"e$sd_turns 15");
-												
-				// various flags
-				sendToEngine(@"e$casefreq 5");
-				
-				// various flags
-				sendToEngine(@"e$template_filter 1");
-								
-				// theme info
-				sendToEngine(@"etheme Freeway");
-				
-				// team 1 info
-				sendToEngine(@"eaddteam 4421353 System Cats");
-				
-				// team 1 grave info
-				sendToEngine(@"egrave star");
-				
-				// team 1 fort info
-				sendToEngine(@"efort  Earth");
-								
-				// team 1 voicepack info
-				sendToEngine(@"evoicepack Classic");
-				
-				// team 1 binds (skipped)				
-				// team 1 members info
-				//for (int i=0; i<4; i++) {
-					sendToEngine(@"eaddhh 0 100 Snow Leopard");
-					sendToEngine(@"ehat NoHat");
-				//}
-				// team 1 ammostore
-				sendToEngine(@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144");
-
-				// team 2 info
-				sendToEngine(@"eaddteam 4100897 Poke-MAN");
-				
-				// team 2 grave info
-				sendToEngine(@"egrave Badger");
-				
-				// team 2 fort info
-				sendToEngine(@"efort UFO");
-				
-				// team 2 voicepack info
-				sendToEngine(@"evoicepack Classic");
-				
-				// team 2 binds (skipped)
-				// team 2 members info
-			//	for (int i=0; i<4; i++) {
-					sendToEngine(@"eaddhh 0 100 Raichu");
-					sendToEngine(@"ehat Bunny");
-			//	}
-				
-				// team 2 ammostore
-				sendToEngine(@"eammstore 93919294221991210322351110012010000002110404000441400444645644444774776112211144");
-				
-				clientQuit = NO;
-			} else {
-				NSLog(@"engineProtocolThread - wrong message, closing connection");
-				clientQuit = YES;
-			}
-			
-			while (!clientQuit){
-				/* Now we can communicate with the client using csd socket
-				 * sd will remain opened waiting other connections */
-				idx = 0;
-				msgSize = 0;
-				memset(buffer, 0, BUFFER_SIZE);
-				memset(string, 0, BUFFER_SIZE);
-				if (SDLNet_TCP_Recv(csd, &msgSize, sizeof(Uint8)) <= 0)
-					clientQuit = YES;
-				if (SDLNet_TCP_Recv(csd, buffer, msgSize) <=0)
-					clientQuit = YES;
-				
-				gameTicks = SDLNet_Read16(&buffer[msgSize - 2]);
-				//NSLog(@"engineProtocolThread - %d: received [%s]", gameTicks, buffer);
-				
-				switch (buffer[0]) {
-					case '?':
-						NSLog(@"Ping? Pong!");
-						sendToEngine(@"!");
-						break;
-					case 'E':
-						NSLog(@"ERROR - last console line: [%s]", buffer);
-						clientQuit = YES;
-						break;
-					case 'e':
-						sscanf(buffer, "%*s %d", &eProto);
-						if (HW_protoVer() == eProto) {
-							NSLog(@"Setting protocol version %s", buffer);
-						} else {
-							NSLog(@"ERROR - wrong protocol number: [%s] - expecting %d", buffer, eProto);
-							clientQuit = YES;
-						}
-						break;
-					default:
-						// empty packet or just statistics
-						break;
-					case 'i':
-						switch (buffer[1]) {
-							case 'r':
-								NSLog(@"Winning team: %s", &buffer[2]);
-								break;
-							case 'k':
-								NSLog(@"Best Hedgehog: %s", &buffer[2]);
-								break;
-						}
-						break;
-					// missing case for exiting
-				} 
-				
-				/*
-				 // Terminate this connection 
-				 if(strcmp(buffer, "exit") == 0)	{
-				 quit2 = 1;
-				 printf("Terminate connection\n");
-				 }
-				 // Quit the thread
-				 if(strcmp(buffer, "quit") == 0)	{
-				 quit2 = 1;
-				 quit = 1;
-				 printf("Quit program\n");
-				 }
-				 */
-			}
-		}
-		
-		/* Close the client socket */
-		SDLNet_TCP_Close(csd);
-	}
-
-	SDLNet_TCP_Close(sd);
-	SDLNet_Quit();
-
-	[pool release];
-	pthread_exit(NULL);
-}
-
-void setupArgsForLocalPlay() {
-	memset(forward_argv, 0, forward_argc);
-	
-	forward_argc = 18;
-	forward_argv = (char **)realloc(forward_argv, forward_argc * sizeof(char *));
-	//forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
-	forward_argv[ 1] = forward_argv[0];	// (UNUSED)
-	forward_argv[ 2] = "320";			// cScreenWidth (NO EFFECT)
-	forward_argv[ 3] = "480";			// cScreenHeight (NO EFFECT)
-	forward_argv[ 4] = "32";			// cBitsStr
-	forward_argv[ 5] = IPC_PORT_STR;	// ipcPort; <- (MAIN TODO)
-	forward_argv[ 6] = "1";				// cFullScreen (NO EFFECT)
-	forward_argv[ 7] = "0";				// isSoundEnabled (TOSET)
-	forward_argv[ 8] = "1";				// cVSyncInUse (UNUSED)
-	forward_argv[ 9] = "en.txt";		// cLocaleFName (TOSET)
-	forward_argv[10] = "100";			// cInitVolume (TOSET)
-	forward_argv[11] = "8";				// cTimerInterval
-	forward_argv[12] = "Data";			// PathPrefix
-	forward_argv[13] = "1";				// cShowFPS (TOSET?)
-	forward_argv[14] = "0";				// cAltDamage (TOSET)
-	forward_argv[15] = "Koda";			// UserNick (DecodeBase64(ParamStr(15)) FTW) <- TODO
-	forward_argv[16] = "0";				// isMusicEnabled (TOSET)
-	forward_argv[17] = "0";				// cReducedQuality
-
-	return;
-}
-
-@end
--- a/hedgewars/uLocale.pas	Tue Jan 12 07:32:15 2010 +0000
+++ b/hedgewars/uLocale.pas	Wed Jan 13 09:41:35 2010 +0000
@@ -47,7 +47,7 @@
 function GetEventString(e: TEventId): string;
 
 implementation
-uses uMisc, uRandom;
+uses uMisc, uRandom, uConsole;
 
 var	trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of string;
 	trevt_n: array[TEventId] of integer;
@@ -62,10 +62,19 @@
 trammo[sidNothing]:= ' ';
 for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
 
-{$I-}
+{$I-} //iochecks off
+filemode:=0; //readonly
 Assign(f, FileName);
 reset(f);
-TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', true);
+// if the locale does not exist, fallback to the default one
+if (IOResult <> 0) then
+begin
+	WriteLnToConsole('Warning: Cannot load selected locale "' + FileName + '" fallback to default en.txt');
+	Assign(f, 'en.txt');
+	reset(f);
+end;
+
+TryDo(IOResult = 0, 'Cannot load locale "' + FileName + ' nor en.txt"', true);
 while not eof(f) do
 	begin
 	readln(f, s);
--- a/hedgewars/uMisc.pas	Tue Jan 12 07:32:15 2010 +0000
+++ b/hedgewars/uMisc.pas	Wed Jan 13 09:41:35 2010 +0000
@@ -588,14 +588,17 @@
 {$I-}
 for i:= 0 to 7 do
 begin
-	assign(f, 
-{$IFDEF IPHONEOS}
-	string(IPH_getDocumentsPath())
+{$IFDEF IPHONEDBG}
+	f:= stderr;
 {$ELSE}
-	ParamStr(1)
+	assign(f, 
+  {$IFDEF IPHONEOS}
+	  string(IPH_getDocumentsPath())
+  {$ELSE}
+	  ParamStr(1)
+  {$ENDIF}
+	  + '/debug' + inttostr(i) + '.txt');
 {$ENDIF}
-	+ '/debug' + inttostr(i) + '.txt');
-//	f:= stderr;
 	rewrite(f);
 	if IOResult = 5 then
 	begin