Exemple #1
0
/*
* TV_Downstream_ChangeStream
*/
qboolean TV_Downstream_ChangeStream( client_t *client, relay_t *relay )
{
	relay_t *oldrelay;

	assert( client );

	oldrelay = client->relay;

	if( relay )
	{
		if( !TV_Relay_CanConnect( relay, client, client->userinfo ) )
			return qfalse;
	}
	else
	{
		if( !TV_Lobby_CanConnect( client, client->userinfo ) )
			return qfalse;
	}

	if( oldrelay )
		TV_Relay_ClientDisconnect( oldrelay, client );
	else
		TV_Lobby_ClientDisconnect( client );

	TV_Downstream_ClientResetCommandBuffers( client, qfalse );

	if( relay )
		TV_Relay_ClientConnect( relay, client );
	else
		TV_Lobby_ClientConnect( client );

	TV_Downstream_SendServerCommand( client, "changing" );
	TV_Downstream_SendServerCommand( client, "reconnect" );
	client->state = CS_CONNECTED;

	return qtrue;
}
/*
* TV_Downstream_ClientConnect
*/
static bool TV_Downstream_ClientConnect( const socket_t *socket, const netadr_t *address, client_t *client,
											char *userinfo, int game_port, int challenge, bool tv_client )
{
	assert( socket );
	assert( address );
	assert( client );
	assert( userinfo );

	// it may actually happen that we reuse a client slot (same IP, same port),
	// which is "attached" to an active relay, so we need to notify the relay that client
	// isn't active anymore, otherwise it'll get confused after we set the client's state 
	// to CS_CONNECTING down below
	if( client->relay )
		TV_Relay_ClientDisconnect( client->relay, client );

	if( !TV_Lobby_CanConnect( client, userinfo ) )
		return false;

	TV_Lobby_ClientConnect( client );

	// the upstream is accepted, set up the client slot
	client->challenge = challenge; // save challenge for checksumming
	client->tv = (tv_client ? true : false);

	switch( socket->type )
	{
#ifdef TCP_ALLOW_TVCONNECT
	case SOCKET_TCP:
		client->reliable = true;
		client->individual_socket = true;
		client->socket = *socket;
		break;
#endif

	case SOCKET_UDP:
	case SOCKET_LOOPBACK:
		client->reliable = false;
		client->individual_socket = false;
		client->socket.open = false;
		break;

	default:
		assert( false );
	}

	TV_Downstream_ClientResetCommandBuffers( client, true );

	// reset timeouts
	client->lastPacketReceivedTime = tvs.realtime;
	client->lastconnect = tvs.realtime;

	// init the upstream
	client->state = CS_CONNECTING;

	if( client->individual_socket )
		Netchan_Setup( &client->netchan, &client->socket, address, game_port );
	else
		Netchan_Setup( &client->netchan, socket, address, game_port );

	// parse some info from the info strings
	Q_strncpyz( client->userinfo, userinfo, sizeof( client->userinfo ) );
	TV_Downstream_UserinfoChanged( client );

	Com_Printf( "%s" S_COLOR_WHITE " connected\n", client->name );

	return true;
}
Exemple #3
0
/*
* TV_Downstream_DropClient
*/
void TV_Downstream_DropClient( client_t *drop, int type, const char *format, ... )
{
	va_list	argptr;
	char string[1024];
	msg_t Message;
	qbyte MessageData[MAX_MSGLEN];

	va_start( argptr, format );
	Q_vsnprintfz( string, sizeof( string ), format, argptr );
	va_end( argptr );

	Com_Printf( "%s" S_COLOR_WHITE " dropped: %s\n", drop->name, string );

	TV_Downstream_InitClientMessage( drop, &Message, MessageData, sizeof( MessageData ) );

	TV_Downstream_SendServerCommand( drop, "disconnect %i \"%s\"", type, string );
	TV_Downstream_AddReliableCommandsToMessage( drop, &Message );

	TV_Downstream_SendMessageToClient( drop, &Message );
	Netchan_PushAllFragments( &drop->netchan );

	if( drop->relay && /*drop->relay->state == CA_ACTIVE && */drop->state >= CS_CONNECTING )
		TV_Relay_ClientDisconnect( drop->relay, drop );

	// make sure everything is clean
	TV_Downstream_ClientResetCommandBuffers( drop, qtrue );

	SNAP_FreeClientFrames( drop );

	if( drop->download.name )
	{
		if( drop->download.data )
		{
			FS_FreeBaseFile( drop->download.data );
			drop->download.data = NULL;
		}

		Mem_ZoneFree( drop->download.name );
		drop->download.name = NULL;

		drop->download.size = 0;
		drop->download.timeout = 0;
	}

	if( drop->individual_socket )
		NET_CloseSocket( &drop->socket );

	if( drop->mv )
	{
		tvs.nummvclients--;
		drop->mv = qfalse;
	}

	memset( &drop->flood, 0, sizeof( drop->flood ) );

	drop->edict = NULL;
	drop->relay = NULL;
	drop->tv = qfalse;
	drop->state = CS_ZOMBIE;    // become free in a few seconds
	drop->name[0] = 0;
}
/*
* TV_Downstream_New_f
* 
* Sends the first message from the server to a connected client.
* This will be sent on the initial upstream and upon each server load.
*/
void TV_Downstream_New_f( client_t *client )
{
	int playernum, numpure;
	int tv_bitflags;
	purelist_t *iter;
	msg_t message;
	uint8_t messageData[MAX_MSGLEN];

	// if in CS_AWAITING we have sended the response packet the new once already,
	// but client might have not got it so we send it again
	if( client->state >= CS_SPAWNED )
	{
		Com_DPrintf( "New not valid -- already spawned\n" );
		return;
	}

	// relay is not ready yet
	if( client->relay && client->relay->state < CA_ACTIVE )
	{
		TV_Relay_DelayNew( client );
		return;
	}

	//
	// serverdata needs to go over for all types of servers
	// to make sure the protocol is right, and to set the gamedir
	//
	TV_Downstream_InitClientMessage( client, &message, messageData, sizeof( messageData ) );

	// send the serverdata
	MSG_WriteByte( &message, svc_serverdata );
	MSG_WriteLong( &message, APP_PROTOCOL_VERSION );
	if( !client->relay )
	{
		MSG_WriteLong( &message, tvs.lobby.spawncount );
		MSG_WriteShort( &message, tvs.lobby.snapFrameTime );
		MSG_WriteString( &message, FS_BaseGameDirectory() );
		MSG_WriteString( &message, FS_GameDirectory() );
	}
	else
	{
		MSG_WriteLong( &message, client->relay->servercount );
		MSG_WriteShort( &message, client->relay->snapFrameTime );
		MSG_WriteString( &message, client->relay->basegame );
		MSG_WriteString( &message, client->relay->game );
	}

	if( client->relay )
	{
		// we use our own playernum on the relay server
		MSG_WriteShort( &message, client->relay->playernum );
	}
	else
	{
		playernum = client - tvs.clients;
		MSG_WriteShort( &message, playernum );
	}

	// send full levelname
	if( !client->relay )
		MSG_WriteString( &message, tv_name->string );
	else
		MSG_WriteString( &message, client->relay->levelname );

	memset( &client->lastcmd, 0, sizeof( client->lastcmd ) );

	tv_bitflags = SV_BITFLAGS_TVSERVER;
	if( client->reliable )
		tv_bitflags |= SV_BITFLAGS_RELIABLE;

	MSG_WriteByte( &message, tv_bitflags ); // sv_bitflags

	// purelist
	if( !client->relay )
	{
		MSG_WriteShort( &message, 0 );
	}
	else
	{
		numpure = Com_CountPureListFiles( client->relay->purelist );

		MSG_WriteShort( &message, numpure );
		iter = client->relay->purelist;
		while( iter )
		{
			MSG_WriteString( &message, iter->filename );
			MSG_WriteLong( &message, iter->checksum );
			iter = iter->next;
		}
	}

	TV_Downstream_ClientResetCommandBuffers( client, true );

	TV_Downstream_SendMessageToClient( client, &message );

	Netchan_PushAllFragments( &client->netchan );

	// don't let it send reliable commands until we get the first configstring request
	client->state = CS_CONNECTING;
}