Beispiel #1
0
void ScummEngine_v71he::o71_compareString() {
	int result;

	int array1 = pop();
	int array2 = pop();

	byte *string1 = getStringAddress(array1);
	if (!string1)
		error("o71_compareString: Reference to zeroed array pointer (%d)", array1);

	byte *string2 = getStringAddress(array2);
	if (!string2)
		error("o71_compareString: Reference to zeroed array pointer (%d)", array2);

	while (*string1 == *string2) {
		if (*string2 == 0) {
			push(0);
			return;
		}

		string1++;
		string2++;
	}

	result = (*string1 > *string2) ? -1 : 1;
	push(result);
}
Beispiel #2
0
void ScummEngine_v70he::o70_getStringLen() {
	int id, len;
	byte *addr;

	id = pop();

	addr = getStringAddress(id);
	if (!addr)
		error("o70_getStringLen: Reference to zeroed array pointer (%d)", id);

	len = resStrLen(getStringAddress(id));
	push(len);
}
Beispiel #3
0
void ScummEngine_v71he::o71_concatString() {
	int dst, size;

	int src2 = pop();
	int src1 = pop();

	size = resStrLen(getStringAddress(src1));
	size += resStrLen(getStringAddress(src2)) + 1;
	dst = setupStringArray(size);

	appendSubstring(dst, src1, 0, -1);
	appendSubstring(dst, src2, 0, -1);

	push(dst);
}
Beispiel #4
0
void ScummEngine_v70he::o70_systemOps() {
	byte *src, string[256];
	int id, len;

	byte subOp = fetchScriptByte();

	switch (subOp) {
	case 158:
		restart();
		break;
	case 160:
		// Confirm shutdown
		quitGame();
		break;
	case 244:
		quitGame();
		break;
	case 250:
		id = pop();
		src = getStringAddress(id);
		len = resStrLen(src) + 1;
		memcpy(string, src, len);
		debug(0, "Start executable (%s)", string);
		break;
	case 251:
		convertMessageToString(_scriptPointer, string, sizeof(string));
		len = resStrLen(_scriptPointer);
		_scriptPointer += len + 1;
		debug(0, "Start executable (%s)", string);
		break;
	case 252:
		convertMessageToString(_scriptPointer, string, sizeof(string));
		len = resStrLen(_scriptPointer);
		_scriptPointer += len + 1;
		debug(0, "Start game (%s)", string);
		break;
	case 253:
		id = pop();
		src = getStringAddress(id);
		len = resStrLen(src) + 1;
		memcpy(string, src, len);
		debug(0, "Start game (%s)", string);
		break;
	default:
		error("o70_systemOps invalid case %d", subOp);
	}
}
Client::Client(TCPsocket * socket_){
	socket = *socket_;
	msg = (char*) malloc(BUFFER_SIZE);
	ID = ++IDCounter;
	startPos = 0;
	recvSize = 0;
	mutex = SDL_CreateMutex();
	address = (char*) malloc(24);
	address = (char*) getStringAddress(*SDLNet_TCP_GetPeerAddress(socket));
}
Beispiel #6
0
void ScummEngine_v71he::o71_copyString() {
	int dst, size;
	int src = pop();

	size = resStrLen(getStringAddress(src)) + 1;
	dst = setupStringArray(size);

	appendSubstring(dst, src, -1, -1);

	push(dst);
}
Beispiel #7
0
void send(	TCPsocket*	sock, 
			char		type, 
	const	void*		data, 
			char		len, 
			bool		outputAllowed ) {
	if ( *sock != NULL ) {
		IPaddress * clientIP = SDLNet_TCP_GetPeerAddress(*sock);
		if (outputAllowed) 
			printf("Sending -> %s : (%c:%X) \"%s\"\n", getStringAddress(*clientIP), type, type, data);
		SDLNet_TCP_Send(*sock, &type,1);
		SDLNet_TCP_Send(*sock, &len, 1);
		SDLNet_TCP_Send(*sock, data, len);
	}
}
Beispiel #8
0
void ScummEngine_v71he::appendSubstring(int dst, int src, int srcOffs, int len) {
	int dstOffs, value;
	int i = 0;

	if (len == -1) {
		len = resStrLen(getStringAddress(src));
		srcOffs = 0;
	}

	dstOffs = resStrLen(getStringAddress(dst));

	len -= srcOffs;
	len++;

	while (i < len) {
		writeVar(0, src);
		value = readArray(0, 0, srcOffs + i);
		writeVar(0, dst);
		writeArray(0, 0, dstOffs + i, value);
		i++;
	}

	writeArray(0, 0, dstOffs + i, 0);
}
Beispiel #9
0
void ScummEngine_v71he::o71_getCharIndexInString() {
	int array, end, len, pos, value;

	value = pop();
	end = pop();
	pos = pop();
	array = pop();

	if (end >= 0) {
		len = resStrLen(getStringAddress(array));
		if (len < end)
			end = len;
	} else {
		end = 0;
	}

	if (pos < 0)
		pos = 0;

	writeVar(0, array);
	if (end > pos) {
		while (end >= pos) {
			if (readArray(0, 0, pos) == value) {
				push(pos);
				return;
			}
			pos++;
		}
	} else {
		while (end <= pos) {
			if (readArray(0, 0, pos) == value) {
				push(pos);
				return;
			}
			pos--;
		}
	}

	push(-1);
}
Beispiel #10
0
void ScummEngine_v71he::o71_getStringLenForWidth() {
	int chr, max;
	int array, len, pos, width = 0;

	max = pop();
	pos = pop();
	array = pop();

	len = resStrLen(getStringAddress(array));

	writeVar(0, array);
	while (pos <= len) {
		chr = readArray(0, 0, pos);
		width += getStringCharWidth(chr);
		if (width >= max) {
			push(pos);
			return;
		}
		pos++;
	}

	push(len);
}
Beispiel #11
0
void ScummEngine_v71he::o71_getStringWidth() {
	int array, pos, len;
	int chr, width = 0;

	len = pop();
	pos = pop();
	array = pop();

	if (len == -1) {
		pos = 0;
		len = resStrLen(getStringAddress(array));
	}

	writeVar(0, array);
	while (pos <= len) {
		chr = readArray(0, 0, pos);
		if (chr == 0)
			break;
		width += getStringCharWidth(chr);
		pos++;
	}

	push(width);
}
Beispiel #12
0
int main( int argc, char * argv[] ) {
	
	IDCounter = 0;
	unsigned char consoleWidth = 60;
	for (Uint8 k = 0; k < 10; k++) {
		const char * newName = GenerateName();
		if ( strlen (newName) > consoleWidth ) {
			consoleWidth = 80;
			printf("\n");
		}
		consoleWidth -= strlen (newName);
		printf( "%s ", newName );
	}
	printf( "\n" );

	printf( "Initializing SDL system... " );
			if(SDL_Init(SDL_INIT_EVERYTHING) == -1)	{printf("\nSDL_Init: %s\n", SDL_GetError());exit(1);	}
			if(SDLNet_Init() == -1 )				{printf("\nSDLNet_Init: %s\n", SDLNet_GetError());exit(2);}	
	printf( "ok.\n" );
	
	printf( "Starting server...\n" );
			//
			//
			if( SDLNet_ResolveHost(&ip, NULL, 3879) < 0 ) {
				printf( "\nSDLNet_ResolveHost: %s\n", SDLNet_GetError());
				exit(1);
			} else {
				//ip.host = convFromIP(127,0,0,1);
				ip.port = 3879;
				printf( "Resolved address: %s\n", getStringAddress(ip));
			}
			socket = SDLNet_TCP_Open( &ip );
			if(!socket ) {
				printf( "\nSDLNet_TCP_Open: %s\n", SDLNet_GetError());
				exit(2);
			}

	printf( "ok.\n");
	
	SDLNet_TCP_AddSocket( socketSet, socket );

	printf("Waiting for clients...\n");

	acceptClientThread = SDL_CreateThread(clientNetLoop, NULL);
	
	updateLoopThread = SDL_CreateThread(updateLoop, NULL);

	char instr = 0;
	for(;;) {
		scanf("%c", &instr);
		if (instr == 'q')
			break;
		if (instr == 'a') {
			send(&lastSocket, 'm', "yopt", 4);
		}
		if (instr == 'b') {
			char * broadcastMsg = (char*)malloc(255);
			broadcastMsg[0] = 1;
			broadcastMsg[1] = 0;
			scanf("%[' 'A-z'\'''!'-'+']s", broadcastMsg);
			broadcast('m', broadcastMsg, strlen(broadcastMsg));
		}
		if (instr == 'w') {
			printf("startPos: %i; recvSize: %i\n", clients[0]->startPos, clients[0]->recvSize);
			for (unsigned char i = 0; i < clients[i]->recvSize; i++) {
				if (	clients[0]->msg[i] != '\n' 
					&&	clients[0]->msg[i] != 10)
					printf("%3i\'%c\'; ", (unsigned char)clients[0]->msg[i], (unsigned char)clients[0]->msg[i]);
				else
					printf("%3i\' \'; ", (unsigned char)clients[0]->msg[i]);
			}
			printf("\n");
		}
		instr = 0;
	}
	terminated = true;
	printf("Terminated.\n");
	int status = 0;
	printf("Wait for accepting thread end. ");
	SDL_WaitThread(acceptClientThread,&status);
	printf("Ended.\nClosing socket. ");
	SDLNet_TCP_Close(socket);
	printf("Closed.\n");
	SDL_Quit();
	return 0x127;
}