本文整理汇总了C++中Info_ValueForKey函数的典型用法代码示例。如果您正苦于以下问题:C++ Info_ValueForKey函数的具体用法?C++ Info_ValueForKey怎么用?C++ Info_ValueForKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Info_ValueForKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClientUserinfoChanged
/*
===========
ClientUserInfoChanged
Called from ClientConnect when the player first connects and
directly by the server system when the player updates a userinfo variable.
The game can override any of the settings and call trap_SetUserinfo
if desired.
============
*/
void ClientUserinfoChanged(int clientNum)
{
gentity_t *ent;
int teamTask, teamLeader, team, health;
char *s;
char model[MAX_QPATH];
char oldname[MAX_STRING_CHARS];
gclient_t *client;
char c1[MAX_INFO_STRING];
char c2[MAX_INFO_STRING];
char redTeam[MAX_INFO_STRING];
char blueTeam[MAX_INFO_STRING];
char userinfo[MAX_INFO_STRING];
ent = g_entities + clientNum;
client = ent->client;
trap_GetUserinfo(clientNum, userinfo, sizeof(userinfo));
// check for malformed or illegal info strings
if(!Info_Validate(userinfo))
{
strcpy(userinfo, "\\name\\badinfo");
}
// check for local client
s = Info_ValueForKey(userinfo, "ip");
if(!strcmp(s, "localhost"))
{
client->pers.localClient = qtrue;
}
// check the item prediction
s = Info_ValueForKey(userinfo, "cg_predictItems");
if(!atoi(s))
{
client->pers.predictItemPickup = qfalse;
}
else
{
client->pers.predictItemPickup = qtrue;
}
// set name
Q_strncpyz(oldname, client->pers.netname, sizeof(oldname));
s = Info_ValueForKey(userinfo, "name");
ClientCleanName(s, client->pers.netname, sizeof(client->pers.netname));
if(client->sess.sessionTeam == TEAM_SPECTATOR)
{
if(client->sess.spectatorState == SPECTATOR_SCOREBOARD)
{
Q_strncpyz(client->pers.netname, "scoreboard", sizeof(client->pers.netname));
}
}
if(client->pers.connected == CON_CONNECTED)
{
if(strcmp(oldname, client->pers.netname))
{
trap_SendServerCommand(-1, va("print \"%s" S_COLOR_WHITE " renamed to %s\n\"", oldname, client->pers.netname));
}
}
// set max health
#ifdef MISSIONPACK
if(client->ps.powerups[PW_GUARD])
{
client->pers.maxHealth = 200;
}
else
{
health = atoi(Info_ValueForKey(userinfo, "handicap"));
client->pers.maxHealth = health;
if(client->pers.maxHealth < 1 || client->pers.maxHealth > 100)
{
client->pers.maxHealth = 100;
}
}
#else
health = atoi(Info_ValueForKey(userinfo, "handicap"));
client->pers.maxHealth = health;
if(client->pers.maxHealth < 1 || client->pers.maxHealth > 100)
{
client->pers.maxHealth = 100;
}
#endif
client->ps.stats[STAT_MAX_HEALTH] = client->pers.maxHealth;
//.........这里部分代码省略.........
示例2: SV_DirectConnect
/*
==================
SV_DirectConnect
A "connect" OOB command has been received
==================
*/
void SV_DirectConnect( netadr_t from, const Cmd::Args& args )
{
char userinfo[ MAX_INFO_STRING ];
int i;
client_t *cl, *newcl;
client_t temp;
sharedEntity_t *ent;
int clientNum;
int version;
int qport;
int challenge;
const char *password;
int startIndex;
bool denied;
char reason[ MAX_STRING_CHARS ];
int count;
const char *ip;
#ifdef HAVE_GEOIP
const char *country = nullptr;
#endif
if ( args.Argc() < 2 )
{
return;
}
Log::Debug( "SVC_DirectConnect ()" );
Q_strncpyz( userinfo, args.Argv(1).c_str(), sizeof( userinfo ) );
// DHM - Nerve :: Update Server allows any protocol to connect
// NOTE TTimo: but we might need to store the protocol around for potential non http/ftp clients
version = atoi( Info_ValueForKey( userinfo, "protocol" ) );
if ( version != PROTOCOL_VERSION )
{
NET_OutOfBandPrint( netsrc_t::NS_SERVER, from, "print\nServer uses protocol version %i (yours is %i).", PROTOCOL_VERSION, version );
Log::Debug( " rejected connect from version %i", version );
return;
}
challenge = atoi( Info_ValueForKey( userinfo, "challenge" ) );
qport = atoi( Info_ValueForKey( userinfo, "qport" ) );
// quick reject
for ( i = 0, cl = svs.clients; i < sv_maxclients->integer; i++, cl++ )
{
// DHM - Nerve :: This check was allowing clients to reconnect after zombietime(2 secs)
//if ( cl->state == CS_FREE ) {
//continue;
//}
if ( NET_CompareBaseAdr( from, cl->netchan.remoteAddress )
&& ( cl->netchan.qport == qport
|| from.port == cl->netchan.remoteAddress.port ) )
{
if ( ( svs.time - cl->lastConnectTime )
< ( sv_reconnectlimit->integer * 1000 ) )
{
Log::Debug( "%s: reconnect rejected: too soon", NET_AdrToString( from ) );
return;
}
break;
}
}
if ( NET_IsLocalAddress( from ) )
{
ip = "localhost";
}
else
{
ip = NET_AdrToString( from );
}
if ( ( strlen( ip ) + strlen( userinfo ) + 4 ) >= MAX_INFO_STRING )
{
NET_OutOfBandPrint( netsrc_t::NS_SERVER, from,
"print\nUserinfo string length exceeded. "
"Try removing setu cvars from your config." );
return;
}
Info_SetValueForKey( userinfo, "ip", ip, false );
// see if the challenge is valid (local clients don't need to challenge)
if ( !NET_IsLocalAddress( from ) )
{
int ping;
for ( i = 0; i < MAX_CHALLENGES; i++ )
{
if ( NET_CompareAdr( from, svs.challenges[ i ].adr ) )
//.........这里部分代码省略.........
示例3: G_InitClientSessionData
// called on a first-time connect
void G_InitClientSessionData( gclient_t *client, char *userinfo, qboolean isBot ) {
clientSession_t *sess = &client->sess;
const char *value;
client->sess.siegeDesiredTeam = TEAM_FREE;
// initial team determination
if ( level.gametype >= GT_TEAM ) {
if ( g_teamAutoJoin.integer && !(g_entities[client - level.clients].r.svFlags & SVF_BOT) ) {
sess->sessionTeam = PickTeam( -1 );
BroadcastTeamChange( client, -1 );
}
else {
// always spawn as spectator in team games
if ( !isBot ) {
sess->sessionTeam = TEAM_SPECTATOR;
}
else {
// bots choose their team on creation
value = Info_ValueForKey( userinfo, "team" );
if ( value[0] == 'r' || value[0] == 'R' ) {
sess->sessionTeam = TEAM_RED;
}
else if ( value[0] == 'b' || value[0] == 'B' ) {
sess->sessionTeam = TEAM_BLUE;
}
else {
sess->sessionTeam = PickTeam( -1 );
}
BroadcastTeamChange( client, -1 );
}
}
}
else {
value = Info_ValueForKey( userinfo, "team" );
if ( value[0] == 's' ) {
// a willing spectator, not a waiting-in-line
sess->sessionTeam = TEAM_SPECTATOR;
}
else {
switch ( level.gametype ) {
default:
case GT_FFA:
case GT_HOLOCRON:
case GT_JEDIMASTER:
case GT_SINGLE_PLAYER:
if ( g_maxGameClients.integer > 0 && level.numNonSpectatorClients >= g_maxGameClients.integer ) {
sess->sessionTeam = TEAM_SPECTATOR;
}
else if ( g_teamAutoJoin.integer == 2 ) {
// force joining in all gametypes
sess->sessionTeam = TEAM_FREE;
}
else if ( !isBot ) {
sess->sessionTeam = TEAM_SPECTATOR;
}
else {
// bots automatically join the game
sess->sessionTeam = TEAM_FREE;
}
break;
case GT_DUEL:
// if the game is full, go into a waiting mode
if ( level.numNonSpectatorClients >= 2 ) {
sess->sessionTeam = TEAM_SPECTATOR;
}
else {
sess->sessionTeam = TEAM_FREE;
}
break;
case GT_POWERDUEL:
{
int loners = 0, doubles = 0;
G_PowerDuelCount( &loners, &doubles, qtrue );
if ( !doubles || loners > (doubles / 2) ) {
sess->duelTeam = DUELTEAM_DOUBLE;
}
else {
sess->duelTeam = DUELTEAM_LONE;
}
sess->sessionTeam = TEAM_SPECTATOR;
}
break;
}
}
}
if ( sess->sessionTeam == TEAM_SPECTATOR ) {
sess->spectatorState = SPECTATOR_FREE;
}
else {
sess->spectatorState = SPECTATOR_NOT;
}
sess->spectatorTime = level.time;
sess->siegeClass[0] = '\0';
//.........这里部分代码省略.........
示例4: G_LogWeaponOutput
//.........这里部分代码省略.........
for (j=0; j<WP_NUM_WEAPONS; j++)
{
if (totalshots[j] > 0)
{
pershot = (float)(totaldamage[j])/(float)(totalshots[j]);
}
else
{
pershot = 0;
}
G_LogPrintf("%15s: Damage: %6d, Kills: %5d, Dmg per Shot: %f\n",
weaponNameFromIndex[j], totaldamage[j], totalkills[j], pershot);
}
G_LogPrintf( "\n****Combat Data By Damage Type:\n" );
for (j=0; j<MOD_MAX; j++)
{
G_LogPrintf("%25s: Damage: %6d, Kills: %5d\n",
modNames[j], totaldamageMOD[j], totalkillsMOD[j]);
}
G_LogPrintf("\n");
// Write the whole weapon statistic log out to a file.
trap_FS_FOpenFile( g_statLogFile.string, &weaponfile, FS_APPEND );
if (!weaponfile) { //failed to open file, let's not crash, shall we?
return;
}
// Write out the level name
trap_GetServerinfo(info, sizeof(info));
strncpy(mapname, Info_ValueForKey( info, "mapname" ), sizeof(mapname)-1);
mapname[sizeof(mapname)-1] = '\0';
Com_sprintf(string, sizeof(string), "\n\n\nLevel:\t%s\n\n\n", mapname);
trap_FS_Write( string, strlen( string ), weaponfile);
// Combat data per character
// Start with Pickups per character
Com_sprintf(string, sizeof(string), "Weapon Pickups per Player:\n\n");
trap_FS_Write( string, strlen( string ), weaponfile);
Com_sprintf(string, sizeof(string), "Player");
trap_FS_Write(string, strlen(string), weaponfile);
for (j=0; j<WP_NUM_WEAPONS; j++)
{
Com_sprintf(string, sizeof(string), "\t%s", weaponNameFromIndex[j]);
trap_FS_Write(string, strlen(string), weaponfile);
}
Com_sprintf(string, sizeof(string), "\n");
trap_FS_Write(string, strlen(string), weaponfile);
// Cycle through each player, give their name and the number of times they picked up each weapon.
for (i=0; i<MAX_CLIENTS; i++)
{
if (G_WeaponLogClientTouch[i])
{ // Ignore any entity/clients we don't care about!
if ( g_entities[i].client )
{
nameptr = g_entities[i].client->pers.netname;
}
示例5: UI_ParseInfos
int UI_ParseInfos( char *buf, int max, char *infos[] ) {
char *token;
int count;
char key[MAX_TOKEN_CHARS];
char info[MAX_INFO_STRING];
count = 0;
while ( 1 ) {
token = COM_Parse( (const char **)&buf );
if ( !token[0] ) {
break;
}
if ( strcmp( token, "{" ) ) {
Com_Printf( "Missing { in info file\n" );
break;
}
if ( count == max ) {
Com_Printf( "Max infos exceeded\n" );
break;
}
info[0] = '\0';
while ( 1 ) {
token = COM_ParseExt( (const char **)&buf, qtrue );
if ( !token[0] ) {
Com_Printf( "Unexpected end of info file\n" );
break;
}
if ( !strcmp( token, "}" ) ) {
break;
}
Q_strncpyz( key, token, sizeof(key) );
token = COM_ParseExt( (const char **)&buf, qfalse );
if ( !token[0] ) {
strcpy( token, "<NULL>" );
}
Info_SetValueForKey( info, key, token );
}
//NOTE: extra space for arena number
infos[count] = (char *)UI_Alloc( strlen( info ) + strlen( "\\num\\" ) + strlen( va( "%d", MAX_ARENAS ) ) + 1 );
if ( infos[count] ) {
strcpy( infos[count], info );
#ifdef _DEBUG
if ( trap->Cvar_VariableValue( "com_buildScript" ) ) {
const char *botFile = Info_ValueForKey( info, "personality" );
if ( botFile && botFile[0] ) {
int fh = 0;
trap->FS_Open( botFile, &fh, FS_READ );
if ( fh ) {
trap->FS_Close( fh );
}
}
}
#endif
count++;
}
}
return count;
}
示例6: ClientUserinfoChanged
/*
* ClientUserinfoChanged
* called whenever the player updates a userinfo variable.
*
* The game can override any of the settings in place
* (forcing skins or names, etc) before copying it off.
*/
void ClientUserinfoChanged( edict_t *ent, char *userinfo )
{
char *s;
char oldname[MAX_INFO_VALUE];
gclient_t *cl;
int rgbcolor, i;
assert( ent && ent->r.client );
assert( userinfo && Info_Validate( userinfo ) );
// check for malformed or illegal info strings
if( !Info_Validate( userinfo ) )
{
trap_DropClient( ent, DROP_TYPE_GENERAL, "Error: Invalid userinfo" );
return;
}
cl = ent->r.client;
// ip
s = Info_ValueForKey( userinfo, "ip" );
if( !s )
{
trap_DropClient( ent, DROP_TYPE_GENERAL, "Error: Server didn't provide client IP" );
return;
}
Q_strncpyz( cl->ip, s, sizeof( cl->ip ) );
// socket
s = Info_ValueForKey( userinfo, "socket" );
if( !s )
{
trap_DropClient( ent, DROP_TYPE_GENERAL, "Error: Server didn't provide client socket" );
return;
}
Q_strncpyz( cl->socket, s, sizeof( cl->socket ) );
// color
s = Info_ValueForKey( userinfo, "color" );
if( s )
rgbcolor = COM_ReadColorRGBString( s );
else
rgbcolor = -1;
if( rgbcolor != -1 )
{
rgbcolor = COM_ValidatePlayerColor( rgbcolor );
Vector4Set( cl->color, COLOR_R( rgbcolor ), COLOR_G( rgbcolor ), COLOR_B( rgbcolor ), 255 );
}
else
{
Vector4Set( cl->color, 255, 255, 255, 255 );
}
// set name, it's validated and possibly changed first
Q_strncpyz( oldname, cl->netname, sizeof( oldname ) );
G_SetName( ent, Info_ValueForKey( userinfo, "name" ) );
if( oldname[0] && Q_stricmp( oldname, cl->netname ) && !cl->isTV && !CheckFlood( ent, false ) )
G_PrintMsg( NULL, "%s%s is now known as %s%s\n", oldname, S_COLOR_WHITE, cl->netname, S_COLOR_WHITE );
if( !Info_SetValueForKey( userinfo, "name", cl->netname ) )
{
trap_DropClient( ent, DROP_TYPE_GENERAL, "Error: Couldn't set userinfo (name)" );
return;
}
// clan tag
G_SetClan( ent, Info_ValueForKey( userinfo, "clan" ) );
// handedness
s = Info_ValueForKey( userinfo, "hand" );
if( !s )
cl->hand = 2;
else
cl->hand = bound( atoi( s ), 0, 2 );
// handicap
s = Info_ValueForKey( userinfo, "handicap" );
if( s )
{
i = atoi( s );
if( i > 90 || i < 0 )
{
G_PrintMsg( ent, "Handicap must be defined in the [0-90] range.\n" );
cl->handicap = 0;
}
else
{
cl->handicap = i;
}
//.........这里部分代码省略.........
示例7: G_AddRandomBot
/*
===============
G_AddRandomBot
===============
*/
void G_AddRandomBot( int team ) {
int i, n, num;
float skill;
char *value, netname[36], *teamstr;
gclient_t *cl;
num = 0;
for ( n = 0; n < g_numBots ; n++ ) {
value = Info_ValueForKey( g_botInfos[n], "name" );
//
for ( i=0 ; i< g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected != CON_CONNECTED ) {
continue;
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
if ( !Q_stricmp( value, cl->pers.netname ) ) {
break;
}
}
if (i >= g_maxclients.integer) {
num++;
}
}
num = random() * num;
for ( n = 0; n < g_numBots ; n++ ) {
value = Info_ValueForKey( g_botInfos[n], "name" );
//
for ( i=0 ; i< g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected != CON_CONNECTED ) {
continue;
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
if ( !Q_stricmp( value, cl->pers.netname ) ) {
break;
}
}
if (i >= g_maxclients.integer) {
num--;
if (num <= 0) {
skill = trap_Cvar_VariableValue( "g_spSkill" );
if (team == TEAM_RED) teamstr = "red";
else if (team == TEAM_BLUE) teamstr = "blue";
else teamstr = "";
Q_strncpyz(netname, value, sizeof(netname));
Q_CleanStr(netname);
trap_SendConsoleCommand( EXEC_INSERT, va("addbot %s %f %s %i\n", netname, skill, teamstr, 0) );
return;
}
}
}
}
示例8: SCR_DrawClients
/*
==================
SCR_DrawClients
draws clients list with selected values from userinfo
==================
*/
void SCR_DrawClients(void)
{
extern sb_showclients;
int uid_w, clients;
int i, y, x;
char line[128], buf[64];
if (!sb_showclients || cls.state == ca_disconnected)
return;
// prepare
clients = 0;
uid_w = 3;
for (i=0; i < MAX_CLIENTS; i++)
{
int w;
if (!cl.players[i].name[0])
continue;
clients++;
w = strlen(va("%d", cl.players[i].userid));
if (w > uid_w)
uid_w = w;
}
y = (vid.height - sb_lines - 8 * (clients + 6));
y = max (y, 0);
x = (vid.width - 320) / 2 + 4;
strlcpy (line, " # ", sizeof (line));
snprintf (buf, sizeof (buf), "%*.*s ", uid_w, uid_w, "uid");
strlcat (line, buf, sizeof (line));
snprintf (buf, sizeof (buf), "%-*.*s ", 16-uid_w, 16-uid_w, "name");
strlcat (line, buf, sizeof (line));
strlcat (line, "team skin rate", sizeof (line));
Draw_String (x, y, line);
y += 8;
strlcpy (line, "\x1D\x1F \x1D", sizeof (line));
snprintf (buf, sizeof (buf), "%*.*s", uid_w-2, uid_w-2, "\x1E\x1E\x1E\x1E");
strlcat (line, buf, sizeof (line));
strlcat (line, "\x1F \x1D", sizeof (line));
snprintf (buf, sizeof (buf), "%*.*s", 16-uid_w-2, 16-uid_w-2, "\x1E\x1E\x1E\x1E\x1E\x1E\x1E\x1E\x1E\x1E\x1E\x1E");
strlcat (line, buf, sizeof (line));
strlcat (line, "\x1F \x1D\x1E\x1E\x1F \x1D\x1E\x1E\x1E\x1E\x1E\x1E\x1F \x1D\x1E\x1E\x1F", sizeof (line));
Draw_String(x, y, line);
y += 8;
for (i=0; i < MAX_CLIENTS; i++)
{
if (!cl.players[i].name[0])
continue;
if (y > vid.height - 8)
break;
line[0] = 0;
snprintf (buf, sizeof (buf), "%2d ", i);
strlcat (line, buf, sizeof (line));
snprintf (buf, sizeof (buf), "%*d ", uid_w, cl.players[i].userid);
strlcat(line, buf, sizeof (line));
snprintf (buf, sizeof (buf), "%-*.*s ", 16-uid_w, 16-uid_w, cl.players[i].name);
strlcat (line, buf, sizeof (line));
snprintf(buf, sizeof (buf), "%-4.4s ", Info_ValueForKey(cl.players[i].userinfo, "team"));
strlcat (line, buf, sizeof (line));
if (cl.players[i].spectator)
strlcpy (buf, "<spec> ", sizeof (buf));
else
snprintf (buf, sizeof (buf), "%-8.8s ", Info_ValueForKey(cl.players[i].userinfo, "skin"));
strlcat (line, buf, sizeof (line));
snprintf (buf, sizeof (buf), "%4d", min(9999, atoi(Info_ValueForKey(cl.players[i].userinfo, "rate"))));
strlcat (line, buf, sizeof (line));
Draw_String (x, y, line);
y += 8;
}
}
示例9: Pickup_PersistantPowerup
int Pickup_PersistantPowerup( gentity_t *ent, gentity_t *other ) {
int clientNum;
char userinfo[MAX_INFO_STRING];
float handicap;
int max;
other->client->ps.stats[STAT_PERSISTANT_POWERUP] = ent->item - bg_itemlist;
other->client->persistantPowerup = ent;
if (ent->item->giTag == PW_GUARD) {
clientNum = other->client->ps.clientNum;
trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
if( handicap<=0.0f || handicap>100.0f) {
handicap = 100.0f;
}
max = (int)(2 * handicap);
other->health = max;
other->client->ps.stats[STAT_HEALTH] = max;
other->client->ps.stats[STAT_MAX_HEALTH] = max;
other->client->ps.stats[STAT_ARMOR] = max;
other->client->pers.maxHealth = max;
} else if (ent->item->giTag == PW_SCOUT) {
clientNum = other->client->ps.clientNum;
trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
if( handicap<=0.0f || handicap>100.0f) {
handicap = 100.0f;
}
other->client->pers.maxHealth = handicap;
other->client->ps.stats[STAT_ARMOR] = 0;
} else if (ent->item->giTag == PW_DOUBLER) {
clientNum = other->client->ps.clientNum;
trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
if( handicap<=0.0f || handicap>100.0f) {
handicap = 100.0f;
}
other->client->pers.maxHealth = handicap;
} else if (ent->item->giTag == PW_ARMORREGEN) {
clientNum = other->client->ps.clientNum;
trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
if( handicap<=0.0f || handicap>100.0f) {
handicap = 100.0f;
}
other->client->pers.maxHealth = handicap;
memset(other->client->ammoTimes, 0, sizeof(other->client->ammoTimes));
} else {
clientNum = other->client->ps.clientNum;
trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) );
handicap = atof( Info_ValueForKey( userinfo, "handicap" ) );
if( handicap<=0.0f || handicap>100.0f) {
handicap = 100.0f;
}
other->client->pers.maxHealth = handicap;
}
return -1;
}
示例10: SV_UserinfoChanged
/*
* SV_UserinfoChanged
*
* Pull specific info from a newly changed userinfo string
* into a more C friendly form.
*/
void SV_UserinfoChanged( client_t *client )
{
char *val;
int ival;
assert( client );
assert( Info_Validate( client->userinfo ) );
if( !client->edict || !( client->edict->r.svflags & SVF_FAKECLIENT ) )
{
// force the IP key/value pair so the game can filter based on ip
if( !Info_SetValueForKey( client->userinfo, "socket", NET_SocketTypeToString( client->netchan.socket->type ) ) )
{
SV_DropClient( client, DROP_TYPE_GENERAL, "Error: Couldn't set userinfo (socket)\n" );
return;
}
if( !Info_SetValueForKey( client->userinfo, "ip", NET_AddressToString( &client->netchan.remoteAddress ) ) )
{
SV_DropClient( client, DROP_TYPE_GENERAL, "Error: Couldn't set userinfo (ip)\n" );
return;
}
}
// mm session
ival = 0;
val = Info_ValueForKey( client->userinfo, "cl_mm_session" );
if( val )
ival = atoi( val );
if( !val || ival != client->mm_session )
Info_SetValueForKey( client->userinfo, "cl_mm_session", va("%d", client->mm_session ) );
// mm login
if( client->mm_login[0] != '\0' ) {
Info_SetValueForKey( client->userinfo, "cl_mm_login", client->mm_login );
}
else {
Info_RemoveKey( client->userinfo, "cl_mm_login" );
}
// call prog code to allow overrides
ge->ClientUserinfoChanged( client->edict, client->userinfo );
if( !Info_Validate( client->userinfo ) )
{
SV_DropClient( client, DROP_TYPE_GENERAL, "Error: Invalid userinfo (after game)" );
return;
}
// we assume that game module deals with setting a correct name
val = Info_ValueForKey( client->userinfo, "name" );
if( !val || !val[0] )
{
SV_DropClient( client, DROP_TYPE_GENERAL, "Error: No name set" );
return;
}
Q_strncpyz( client->name, val, sizeof( client->name ) );
#ifndef RATEKILLED
// rate command
if( NET_IsLANAddress( &client->netchan.remoteAddress ) )
{
client->rate = 99999; // lans should not rate limit
}
else
{
val = Info_ValueForKey( client->userinfo, "rate" );
if( val && val[0] )
{
int newrate;
newrate = atoi( val );
if( sv_maxrate->integer && newrate > sv_maxrate->integer )
newrate = sv_maxrate->integer;
else if( newrate > 90000 )
newrate = 90000;
if( newrate < 1000 )
newrate = 1000;
if( client->rate != newrate )
{
client->rate = newrate;
Com_Printf( "%s%s has rate %i\n", client->name, S_COLOR_WHITE, client->rate );
}
}
else
client->rate = 5000;
}
#endif
}
示例11: G_ParseMapSettings
qboolean G_ParseMapSettings(int handle, config_t *config)
{
pc_token_t token;
char serverinfo[MAX_INFO_STRING];
char *mapname;
trap_GetServerinfo(serverinfo, sizeof(serverinfo));
mapname = Info_ValueForKey(serverinfo, "mapname");
if (!trap_PC_ReadToken(handle, &token))
{
G_Printf("Malformed map config\n");
}
G_Printf("Map settings for: %s\n", token.string);
G_Printf("Current map: %s\n", mapname);
if (!Q_stricmp(token.string, "default"))
{
G_Printf("Setting rules for map: %s\n", token.string);
return G_ParseSettings(handle, qtrue, config);
}
else if (!Q_stricmp(token.string, mapname))
{
fileHandle_t f;
char *code, *signature;
qboolean res = qfalse;
G_Printf("Setting rules for map: %s\n", token.string);
res = G_ParseSettings(handle, qtrue, config);
if (res && strlen(config->mapscripthash))
{
char sdir[MAX_QPATH];
int flen = 0;
trap_Cvar_VariableStringBuffer("g_mapScriptDirectory", sdir, sizeof(sdir));
flen = trap_FS_FOpenFile(va("%s/%s.script", sdir, mapname), &f, FS_READ);
if (flen < 0)
{
// FIXME: handle this properly..
//return G_ConfigError(handle, "Cannot open mapscript file for hash verification: %s/%s.script", sdir, mapname);
G_Printf("Cannot open mapscript file for hash verification: %s/%s.script", sdir, mapname);
return res;
}
code = malloc(flen + 1);
trap_FS_Read(code, flen, f);
*(code + flen) = '\0';
trap_FS_FCloseFile(f);
signature = G_SHA1(code);
free(code);
if (Q_stricmp(config->mapscripthash, signature))
{
return G_ConfigError(handle, "Invalid mapscript hash for map: %s hash given in config: \"%s\" scripts actual hash \"%s\"", mapname, config->mapscripthash, signature);
}
G_Printf("Hash is valid for map: %s\n", mapname);
}
return res;
}
else
{
G_Printf("Ignoring rules for map: %s\n", token.string);
return G_ParseSettings(handle, qfalse, config);
}
}
示例12: Com_sprintf
void CRMLandScape::LoadMiscentDef(const char *td)
{
char miscentDef[MAX_QPATH];
CGenericParser2 parse;
CGPGroup *basegroup, *classes, *items, *model;
CGPValue *pair;
Com_sprintf(miscentDef, MAX_QPATH, "ext_data/RMG/%s.miscents", Info_ValueForKey(td, "miscentDef"));
Com_DPrintf("CG_Terrain: Loading and parsing miscentDef %s.....\n", Info_ValueForKey(td, "miscentDef"));
if(!Com_ParseTextFile(miscentDef, parse))
{
Com_sprintf(miscentDef, MAX_QPATH, "ext_data/arioche/%s.miscents", Info_ValueForKey(td, "miscentDef"));
if(!Com_ParseTextFile(miscentDef, parse))
{
Com_Printf("Could not open %s\n", miscentDef);
return;
}
}
// The whole file....
basegroup = parse.GetBaseParseGroup();
// The root { } struct
classes = basegroup->GetSubGroups();
while(classes)
{
items = classes->GetSubGroups();
while(items)
{
if(!Q_stricmp(items->GetName(), "miscent"))
{
int height, maxheight;
// Height must exist - the rest are optional
height = atol(items->FindPairValue("height", "0"));
maxheight = atol(items->FindPairValue("maxheight", "255"));
model = items->GetSubGroups();
while(model)
{
if(!Q_stricmp(model->GetName(), "model"))
{
CRandomModel hd;
// Set defaults
hd.SetModel("");
hd.SetFrequency(1.0f);
hd.SetMinScale(1.0f);
hd.SetMaxScale(1.0f);
pair = model->GetPairs();
while(pair)
{
if(!Q_stricmp(pair->GetName(), "name"))
{
hd.SetModel(pair->GetTopValue());
}
else if(!Q_stricmp(pair->GetName(), "frequency"))
{
hd.SetFrequency((float)atof(pair->GetTopValue()));
}
else if(!Q_stricmp(pair->GetName(), "minscale"))
{
hd.SetMinScale((float)atof(pair->GetTopValue()));
}
else if(!Q_stricmp(pair->GetName(), "maxscale"))
{
hd.SetMaxScale((float)atof(pair->GetTopValue()));
}
pair = (CGPValue *)pair->GetNext();
}
AddModel(height, maxheight, &hd);
}
model = (CGPGroup *)model->GetNext();
}
}
items = (CGPGroup *)items->GetNext();
}
classes = (CGPGroup *)classes->GetNext();
}
Com_ParseTextFileDestroy(parse);
}
示例13: CG_ParseFireteams
// Parses fireteam servercommand
void CG_ParseFireteams() {
int i, j;
const char* s;
const char* p;
int clnts[2];
qboolean onFireteam2;
qboolean isLeader2;
// qboolean onFireteam = CG_IsOnFireteam( cg.clientNum ) ? qtrue : qfalse;
// qboolean isLeader = CG_IsFireTeamLeader( cg.clientNum ) ? qtrue : qfalse;
for ( i = 0; i < MAX_CLIENTS; i++ ) {
cgs.clientinfo[i].fireteamData = NULL;
}
for ( i = 0; i < MAX_FIRETEAMS; i++ ) {
char hexbuffer[11] = "0x00000000";
p = CG_ConfigString( CS_FIRETEAMS + i );
/* s = Info_ValueForKey(p, "n");
if(!s || !*s) {
cg.fireTeams[i].inuse = qfalse;
continue;
} else {
cg.fireTeams[i].inuse = qtrue;
}*/
// Q_strncpyz(cg.fireTeams[i].name, s, 32);
// CG_Printf("Fireteam: %s\n", cg.fireTeams[i].name);
j = atoi( Info_ValueForKey( p, "id" ) );
if ( j == -1 ) {
cg.fireTeams[i].inuse = qfalse;
continue;
} else {
cg.fireTeams[i].inuse = qtrue;
cg.fireTeams[i].ident = j;
}
s = Info_ValueForKey( p, "l" );
cg.fireTeams[i].leader = atoi( s );
s = Info_ValueForKey( p, "c" );
Q_strncpyz( hexbuffer + 2, s, 9 );
sscanf( hexbuffer, "%x", &clnts[1] );
Q_strncpyz( hexbuffer + 2, s + 8, 9 );
sscanf( hexbuffer, "%x", &clnts[0] );
for ( j = 0; j < MAX_CLIENTS; j++ ) {
if ( COM_BitCheck( clnts, j ) ) {
cg.fireTeams[i].joinOrder[j] = qtrue;
cgs.clientinfo[j].fireteamData = &cg.fireTeams[i];
// CG_Printf("%s\n", cgs.clientinfo[j].name);
} else {
cg.fireTeams[i].joinOrder[j] = qfalse;
}
}
}
CG_SortClientFireteam();
onFireteam2 = CG_IsOnFireteam( cg.clientNum ) ? qtrue : qfalse;
isLeader2 = CG_IsFireTeamLeader( cg.clientNum ) ? qtrue : qfalse;
}
示例14: G_InitClientSessionData
// Called on a first-time connect
void G_InitClientSessionData( gclient_t *client, char *userinfo, qboolean isBot ) {
clientSession_t *sess = &client->sess;
const char *value;
client->sess.siegeDesiredTeam = TEAM_FREE;
// initial team determination
if ( level.gametype >= GT_TEAM ) {
if ( g_teamAutoJoin.integer && !(g_entities[client-level.clients].r.svFlags & SVF_BOT) ) {
sess->sessionTeam = PickTeam( -1 );
client->ps.fd.forceDoInit = 1; //every time we change teams make sure our force powers are set right
} else {
// always spawn as spectator in team games
if (!isBot)
{
sess->sessionTeam = TEAM_SPECTATOR;
}
else
{ //Bots choose their team on creation
value = Info_ValueForKey( userinfo, "team" );
if (value[0] == 'r' || value[0] == 'R')
{
sess->sessionTeam = TEAM_RED;
}
else if (value[0] == 'b' || value[0] == 'B')
{
sess->sessionTeam = TEAM_BLUE;
}
else
{
sess->sessionTeam = PickTeam( -1 );
}
client->ps.fd.forceDoInit = 1; //every time we change teams make sure our force powers are set right
}
}
} else {
value = Info_ValueForKey( userinfo, "team" );
if ( value[0] == 's' ) {
// a willing spectator, not a waiting-in-line
sess->sessionTeam = TEAM_SPECTATOR;
} else {
switch ( level.gametype ) {
default:
case GT_FFA:
case GT_SINGLE_PLAYER:
if ( g_maxGameClients.integer > 0 &&
level.numNonSpectatorClients >= g_maxGameClients.integer ) {
sess->sessionTeam = TEAM_SPECTATOR;
} else {
sess->sessionTeam = TEAM_FREE;
}
break;
case GT_DUEL:
// if the game is full, go into a waiting mode
if ( level.numNonSpectatorClients >= 2 ) {
sess->sessionTeam = TEAM_SPECTATOR;
} else {
sess->sessionTeam = TEAM_FREE;
}
break;
case GT_POWERDUEL:
//sess->duelTeam = DUELTEAM_LONE; //default
{
int loners = 0;
int doubles = 0;
G_PowerDuelCount(&loners, &doubles, qtrue);
if (!doubles || loners > (doubles/2))
{
sess->duelTeam = DUELTEAM_DOUBLE;
}
else
{
sess->duelTeam = DUELTEAM_LONE;
}
}
sess->sessionTeam = TEAM_SPECTATOR;
break;
}
}
}
sess->spectatorState = SPECTATOR_FREE;
AddTournamentQueue(client);
sess->siegeClass[0] = 0;
G_WriteClientSessionData( client );
}
示例15: G_InitSessionData
/*
================
G_InitSessionData
Called on a first-time connect
================
*/
void G_InitSessionData( gclient_t *client, char *userinfo, qboolean isBot ) {
clientSession_t *sess;
const char *value;
sess = &client->sess;
// initial team determination
if ( g_gametype.integer >= GT_TEAM ) {
if ( g_teamAutoJoin.integer ) {
sess->sessionTeam = PickTeam( -1 );
BroadcastTeamChange( client, -1 );
} else {
// always spawn as spectator in team games
if (!isBot)
{
sess->sessionTeam = TEAM_SPECTATOR;
}
else
{ //Bots choose their team on creation
value = Info_ValueForKey( userinfo, "team" );
if (value[0] == 'r' || value[0] == 'R')
{
sess->sessionTeam = TEAM_RED;
}
else if (value[0] == 'b' || value[0] == 'B')
{
sess->sessionTeam = TEAM_BLUE;
}
else
{
sess->sessionTeam = PickTeam( -1 );
}
BroadcastTeamChange( client, -1 );
}
}
} else {
value = Info_ValueForKey( userinfo, "team" );
if ( value[0] == 's' ) {
// a willing spectator, not a waiting-in-line
sess->sessionTeam = TEAM_SPECTATOR;
} else {
switch ( g_gametype.integer ) {
default:
case GT_FFA:
case GT_HOLOCRON:
case GT_JEDIMASTER:
case GT_SINGLE_PLAYER:
if ( g_maxGameClients.integer > 0 &&
level.numNonSpectatorClients >= g_maxGameClients.integer ) {
sess->sessionTeam = TEAM_SPECTATOR;
} else {
sess->sessionTeam = TEAM_FREE;
}
break;
case GT_TOURNAMENT:
// if the game is full, go into a waiting mode
if ( level.numNonSpectatorClients >= 2 ) {
sess->sessionTeam = TEAM_SPECTATOR;
} else {
sess->sessionTeam = TEAM_FREE;
}
break;
}
}
}
sess->spectatorState = SPECTATOR_FREE;
sess->spectatorTime = level.time;
G_WriteClientSessionData( client );
}