コード例 #1
0
void SendSpawnMessage(int id, unsigned short x, unsigned short y){
	stream* buf = init_stream(NULL);
	byte buffer[] = {0x15,id,SHORT(x),SHORT(y),50,0,SHORT(player[id].money),STARTWEAPONS_COUNT};
	Stream.write(buf, buffer, 11);
	int i;
	for (i = 0; i < STARTWEAPONS_COUNT; i++){
		Stream.write_byte(buf, startweapons[i]);
		GivePlayerWeapon(id, startweapons[i]);
		if (startweapons[i] == 50) player[id].actualweapon = i; //else 0
	}

	SendToAll(buf->mem, buf->size, 1);
	free(buf);
}
コード例 #2
0
void SendSpawnMessage(int id, unsigned short x, unsigned short y,
		int writesocket)
{
	int stringsize = 11;
	unsigned char *buffer = malloc(stringsize);
	if (buffer == NULL)
		error_exit("Memory error ( SendSpawnMessage() )\n");

	int position = 0;

	unsigned short *spawnx = &x;
	unsigned short *spawny = &y;
	unsigned short *pmoney = &player[id].money;

	buffer[position] = 21;
	position++;
	buffer[position] = id;
	position++;
	memcpy(buffer + position, spawnx, 2);
	position += 2;
	memcpy(buffer + position, spawny, 2);
	position += 2;
	buffer[position] = 50; //Team
	position++;
	buffer[position] = 0;
	position++;
	/*
	 buffer[position] = pmoney[1]; //Money
	 position++;
	 buffer[position] = pmoney[0]; // Money
	 position++;
	 */
	memcpy(buffer + position, pmoney, 2);
	position += 2;

	int i, count;
	count = STARTWEAPONS_COUNT;//sizeof(startweapons)/sizeof(startweapons[0]);
	buffer[position] = count;
	position++;

	buffer = realloc(buffer, stringsize + count);
	if (buffer == NULL)
		error_exit("Memory error ( SendSpawnMessage() )\n");

	for (i = 0; i <= count - 1; i++)
	{
		buffer[position] = startweapons[i];
		position++;

		GivePlayerWeapon(id, startweapons[i]);
		if (startweapons[i] == 50)
			player[id].actualweapon = i; //else 0
	}

	/*
	 int count, i;
	 count = 0;
	 for(i = 0; i <= 10; i++)
	 {
	 if(player[id].slot[i].id != 0)
	 {
	 count++;
	 }
	 }
	 buffer[position] = count; //Count
	 position++;

	 buffer = realloc(buffer, stringsize + count);
	 if (buffer == NULL) error_exit("Memory error ( SendSpawnMessage() )\n");

	 for(i = 0; i <= 10; i++)
	 {
	 if(player[id].slot[i].id != 0)
	 {
	 buffer[position] = player[id].slot[i].id;
	 position++;
	 }
	 }
	 */

	SendToAll(buffer, stringsize + count, 1, writesocket);

	free(buffer);
}