本文整理汇总了C++中Com_sprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ Com_sprintf函数的具体用法?C++ Com_sprintf怎么用?C++ Com_sprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Com_sprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _buildFileList
int _buildFileList(const char* path, bool insert, bool buildList)
{
WIN32_FIND_DATA data;
char spec[MAX_OSPATH];
int count = 0;
// Look for all files
Com_sprintf(spec, sizeof(spec), "%s\\*.*", path);
HANDLE h = FindFirstFile(spec, &data);
while (h != INVALID_HANDLE_VALUE)
{
char full[MAX_OSPATH];
Com_sprintf(full, sizeof(full), "%s\\%s", path, data.cFileName);
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// Directory -- lets go recursive
if (data.cFileName[0] != '.') {
count += _buildFileList(full, insert, buildList);
}
}
else
{
if(insert || buildList)
{
// Regular file -- add it to the table
strlwr(full);
unsigned int code = crc32(0, (const byte *)full, strlen(full));
FileInfo info;
info.name = CopyString(full);
info.size = data.nFileSizeLow;
if(insert)
{
s_Files->Insert(info, code);
}
if(buildList)
{
// get the length of the filename
int len;
len = strlen(info.name) + 1;
// save the file code
*(int*)buffer = code;
buffer += sizeof(code);
// save the name of the file
strcpy((char*)buffer,info.name);
buffer += len;
// save the size of the file
*(int*)buffer = info.size;
buffer += sizeof(info.size);
}
}
count++;
}
// Continue the loop
if (!FindNextFile(h, &data))
{
FindClose(h);
return count;
}
}
return count;
}
示例2: UpdateTournamentInfo
/*
==================
UpdateTournamentInfo
==================
*/
void UpdateTournamentInfo(void)
{
int i;
gentity_t *player;
int playerClientNum;
int n, accuracy, perfect, msglen;
int buflen;
int score1, score2;
qboolean won;
char buf[32];
char msg[MAX_STRING_CHARS];
// find the real player
player = NULL;
for(i = 0; i < level.maxclients; i++)
{
player = &g_entities[i];
if(!player->inuse)
{
continue;
}
if(!(player->r.svFlags & SVF_BOT))
{
break;
}
}
// this should never happen!
if(!player || i == level.maxclients)
{
return;
}
playerClientNum = i;
CalculateRanks();
if(level.clients[playerClientNum].sess.sessionTeam == TEAM_SPECTATOR)
{
Com_sprintf(msg, sizeof(msg), "postgame %i %i 0 0 0 0 0 0 0 0 0 0 0 0", level.numNonSpectatorClients, playerClientNum);
}
else
{
if(player->client->accuracy_shots)
{
accuracy = player->client->accuracy_hits * 100 / player->client->accuracy_shots;
}
else
{
accuracy = 0;
}
won = qfalse;
if(g_gametype.integer >= GT_CTF)
{
score1 = level.teamScores[TEAM_RED];
score2 = level.teamScores[TEAM_BLUE];
if(level.clients[playerClientNum].sess.sessionTeam == TEAM_RED)
{
won = (level.teamScores[TEAM_RED] > level.teamScores[TEAM_BLUE]);
}
else
{
won = (level.teamScores[TEAM_BLUE] > level.teamScores[TEAM_RED]);
}
}
else
{
if(&level.clients[playerClientNum] == &level.clients[level.sortedClients[0]])
{
won = qtrue;
score1 = level.clients[level.sortedClients[0]].ps.persistant[PERS_SCORE];
score2 = level.clients[level.sortedClients[1]].ps.persistant[PERS_SCORE];
}
else
{
score2 = level.clients[level.sortedClients[0]].ps.persistant[PERS_SCORE];
score1 = level.clients[level.sortedClients[1]].ps.persistant[PERS_SCORE];
}
}
if(won && player->client->ps.persistant[PERS_KILLED] == 0)
{
perfect = 1;
}
else
{
perfect = 0;
}
Com_sprintf(msg, sizeof(msg), "postgame %i %i %i %i %i %i %i %i %i %i %i %i %i %i",
level.numNonSpectatorClients,
playerClientNum,
accuracy,
player->client->ps.persistant[PERS_IMPRESSIVE_COUNT],
player->client->ps.persistant[PERS_EXCELLENT_COUNT],
//.........这里部分代码省略.........
示例3: func_clock_think
void
func_clock_think (edict_t * self)
{
if (!self->enemy)
{
self->enemy = G_Find (NULL, FOFS (targetname), self->target);
if (!self->enemy)
return;
}
if (self->spawnflags & 1)
{
func_clock_format_countdown (self);
self->health++;
}
else if (self->spawnflags & 2)
{
func_clock_format_countdown (self);
self->health--;
}
else
{
struct tm *ltime;
time_t gmtime;
time (&gmtime);
ltime = localtime (&gmtime);
Com_sprintf (self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i:%2i",
ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
if (self->message[3] == ' ')
self->message[3] = '0';
if (self->message[6] == ' ')
self->message[6] = '0';
}
self->enemy->message = self->message;
self->enemy->use (self->enemy, self, self);
if (((self->spawnflags & 1) && (self->health > self->wait)) ||
((self->spawnflags & 2) && (self->health < self->wait)))
{
if (self->pathtarget)
{
char *savetarget;
char *savemessage;
savetarget = self->target;
savemessage = self->message;
self->target = self->pathtarget;
self->message = NULL;
G_UseTargets (self, self->activator);
self->target = savetarget;
self->message = savemessage;
}
if (!(self->spawnflags & 8))
return;
func_clock_reset (self);
if (self->spawnflags & 4)
return;
}
self->nextthink = level.time + 1;
}
示例4: UI_ReadLegalForce
//Mostly parts of other functions merged into one another.
//Puts the current UI stuff into a string, legalizes it, and then reads it back out.
void UI_ReadLegalForce(void)
{
char fcfString[512];
char forceStringValue[4];
int strPlace = 0;
int forcePlace = 0;
int i = 0;
char singleBuf[64];
char info[MAX_INFO_VALUE];
int c = 0;
int iBuf = 0;
int forcePowerRank = 0;
int currank = 0;
int forceTeam = 0;
qboolean updateForceLater = qfalse;
//First, stick them into a string.
Com_sprintf(fcfString, sizeof(fcfString), "%i-%i-", uiForceRank, uiForceSide);
strPlace = strlen(fcfString);
while (forcePlace < NUM_FORCE_POWERS)
{
Com_sprintf(forceStringValue, sizeof(forceStringValue), "%i", uiForcePowersRank[forcePlace]);
//Just use the force digit even if multiple digits. Shouldn't be longer than 1.
fcfString[strPlace] = forceStringValue[0];
strPlace++;
forcePlace++;
}
fcfString[strPlace] = '\n';
fcfString[strPlace+1] = 0;
info[0] = '\0';
trap_GetConfigString(CS_SERVERINFO, info, sizeof(info));
if (atoi( Info_ValueForKey( info, "g_forceBasedTeams" ) ))
{
switch((int)(trap_Cvar_VariableValue("ui_myteam")))
{
case TEAM_RED:
forceTeam = FORCE_DARKSIDE;
break;
case TEAM_BLUE:
forceTeam = FORCE_LIGHTSIDE;
break;
default:
break;
}
}
//Second, legalize them.
if (!BG_LegalizedForcePowers(fcfString, uiMaxRank, ui_freeSaber.integer, forceTeam, atoi( Info_ValueForKey( info, "g_gametype" )), 0))
{ //if they were illegal, we should refresh them.
updateForceLater = qtrue;
}
//Lastly, put them back into the UI storage from the legalized string
i = 0;
while (fcfString[i] && fcfString[i] != '-')
{
singleBuf[c] = fcfString[i];
c++;
i++;
}
singleBuf[c] = 0;
c = 0;
i++;
iBuf = atoi(singleBuf);
if (iBuf > uiMaxRank || iBuf < 0)
{ //this force config uses a rank level higher than our currently restricted level.. so we can't use it
//FIXME: Print a message indicating this to the user
// return;
}
uiForceRank = iBuf;
while (fcfString[i] && fcfString[i] != '-')
{
singleBuf[c] = fcfString[i];
c++;
i++;
}
singleBuf[c] = 0;
c = 0;
i++;
uiForceSide = atoi(singleBuf);
if (uiForceSide != FORCE_LIGHTSIDE &&
uiForceSide != FORCE_DARKSIDE)
{
uiForceSide = FORCE_LIGHTSIDE;
return;
}
//clear out the existing powers
while (c < NUM_FORCE_POWERS)
//.........这里部分代码省略.........
示例5: CL_cURL_BeginDownload
void CL_cURL_BeginDownload( const char *localName, const char *remoteURL )
{
clc.cURLUsed = qtrue;
Com_Printf("URL: %s\n", remoteURL);
Com_DPrintf("***** CL_cURL_BeginDownload *****\n"
"Localname: %s\n"
"RemoteURL: %s\n"
"****************************\n", localName, remoteURL);
CL_cURL_Cleanup();
Q_strncpyz(clc.downloadURL, remoteURL, sizeof(clc.downloadURL));
Q_strncpyz(clc.downloadName, localName, sizeof(clc.downloadName));
Com_sprintf(clc.downloadTempName, sizeof(clc.downloadTempName),
"%s.tmp", localName);
// Set so UI gets access to it
Cvar_Set("cl_downloadName", localName);
Cvar_Set("cl_downloadSize", "0");
Cvar_Set("cl_downloadCount", "0");
Cvar_SetValue("cl_downloadTime", cls.realtime);
clc.downloadBlock = 0; // Starting new file
clc.downloadCount = 0;
clc.downloadCURL = qcurl_easy_init();
if(!clc.downloadCURL) {
Com_Error(ERR_DROP, "CL_cURL_BeginDownload: qcurl_easy_init() "
"failed\n");
return;
}
clc.download = FS_SV_FOpenFileWrite(clc.downloadTempName);
if(!clc.download) {
Com_Error(ERR_DROP, "CL_cURL_BeginDownload: failed to open "
"%s for writing\n", clc.downloadTempName);
return;
}
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_WRITEDATA, clc.download);
if(com_developer->integer)
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_VERBOSE, 1);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_URL, clc.downloadURL);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_TRANSFERTEXT, 0);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_REFERER, va("ioQ3://%s",
NET_AdrToString(clc.serverAddress)));
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_USERAGENT, va("%s %s",
Q3_VERSION, qcurl_version()));
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_WRITEFUNCTION,
CL_cURL_CallbackWrite);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_WRITEDATA, &clc.download);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_NOPROGRESS, 0);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_PROGRESSFUNCTION,
CL_cURL_CallbackProgress);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_PROGRESSDATA, NULL);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_FAILONERROR, 1);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_FOLLOWLOCATION, 1);
qcurl_easy_setopt(clc.downloadCURL, CURLOPT_MAXREDIRS, 5);
clc.downloadCURLM = qcurl_multi_init();
if(!clc.downloadCURLM) {
qcurl_easy_cleanup(clc.downloadCURL);
clc.downloadCURL = NULL;
Com_Error(ERR_DROP, "CL_cURL_BeginDownload: qcurl_multi_init() "
"failed\n");
return;
}
qcurl_multi_add_handle(clc.downloadCURLM, clc.downloadCURL);
if(!(clc.sv_allowDownload & DLF_NO_DISCONNECT) &&
!clc.cURLDisconnected) {
CL_AddReliableCommand("disconnect", qtrue);
CL_WritePacket();
CL_WritePacket();
CL_WritePacket();
clc.cURLDisconnected = qtrue;
}
}
示例6: CG_ChatboxAdd
// This function is called recursively when a logical message has to be split into multiple lines
void CG_ChatboxAdd( const char *message, qboolean multiLine ) {
chatEntry_t *chat = &chatbox.chatBuffer[MAX_CHATBOX_ENTRIES-1];
size_t strLength = 0;
int i = 0;
float accumLength = 0.0f;
chatbox.numActiveLines++;
//Stop scrolling up if we've already scrolled, similar to console behaviour
if ( chatbox.scrollAmount < 0 )
chatbox.scrollAmount = MAX( chatbox.scrollAmount - 1, chatbox.numActiveLines >= cg_chatboxLineCount->integer ? ((MIN(chatbox.numActiveLines, MAX_CHATBOX_ENTRIES)-cg_chatboxLineCount->integer)*-1) : 0 ); //cb->scrollAmount--;
for ( i=0, strLength=strlen( message );
i<strLength && i<CHAT_MESSAGE_LENGTH;
i++ )
{
char *p = (char*)&message[i];
char buf[1];
buf[0] = *p;
if ( !Q_IsColorString( p ) && (i > 0 && !Q_IsColorString( p-1 )) )
accumLength += CG_Text_Width( buf, CHATBOX_FONT_SCALE, -1 );
if ( accumLength > SCREEN_WIDTH && (i>0 && !Q_IsColorString( p-1 )) ) {
char lastColor = '2';
int j = i;
int savedOffset = i;
char tempMessage[CHAT_MESSAGE_LENGTH];
//Attempt to back-track, find a space (' ') within X characters or pixels
//RAZTODO: Another method using character width? Meh
while ( message[i] != ' ' )
{
if ( i <= 0 || i < savedOffset-16 )
{
i = j = savedOffset;
break;
}
i--;
j--;
}
memmove( &chatbox.chatBuffer[0], &chatbox.chatBuffer[1], sizeof( chatbox.chatBuffer ) - sizeof( chatEntry_t ) );
memset( chat, 0, sizeof( chatEntry_t ) ); //Clear the last element, ready for writing
Q_strncpyz( chat->message, message, i+1 );
chat->time = cg.time + cg_chatboxMsgTime->integer*1000;
chat->isUsed = qtrue;
for ( j=i; j>=0; j-- )
{
if ( message[j] == '^' && message[j+1] >= '0' && message[j+1] <= '9' )
{
lastColor = message[j+1];
break;
}
}
Com_sprintf( tempMessage, sizeof( tempMessage ), "^%c%s", lastColor, (const char *)(message + i) );
//Recursively insert until we don't have to split the message
CG_ChatboxAdd( tempMessage, qtrue );
return;
}
}
memmove( &chatbox.chatBuffer[0], &chatbox.chatBuffer[1], sizeof( chatbox.chatBuffer ) - sizeof( chatEntry_t ) );
memset( chat, 0, sizeof( chatEntry_t ) ); //Clear the last element, ready for writing
Q_strncpyz( chat->message, message, i+1 );
chat->time = cg.time + cg_chatboxMsgTime->integer*1000;
chat->isUsed = qtrue;
}
示例7: SV_InitGame
/*
==============
SV_InitGame
A brand new game has been started
==============
*/
void SV_InitGame (void)
{
int i;
edict_t *ent;
char idmaster[32];
if (svs.initialized)
{
// cause any connected clients to reconnect
SV_Shutdown ("Server restarted\n", true);
}
else
{
// make sure the client is down
CL_Drop ();
SCR_BeginLoadingPlaque ();
}
// get any latched variable changes (maxclients, etc)
Cvar_GetLatchedVars ();
svs.initialized = true;
if (Cvar_VariableValue ("coop") && Cvar_VariableValue ("deathmatch"))
{
Com_Printf("Deathmatch and Coop both set, disabling Coop\n");
Cvar_FullSet ("coop", "0", CVAR_SERVERINFO | CVAR_LATCH);
}
// dedicated servers are can't be single player and are usually DM
// so unless they explicity set coop, force it to deathmatch
if (dedicated->value)
{
if (!Cvar_VariableValue ("coop"))
Cvar_FullSet ("deathmatch", "1", CVAR_SERVERINFO | CVAR_LATCH);
}
// init clients
if (Cvar_VariableValue ("deathmatch"))
{
if (maxclients->value <= 1)
Cvar_FullSet ("maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
else if (maxclients->value > MAX_CLIENTS)
Cvar_FullSet ("maxclients", va("%i", MAX_CLIENTS), CVAR_SERVERINFO | CVAR_LATCH);
}
else if (Cvar_VariableValue ("coop"))
{
if (maxclients->value <= 1 || maxclients->value > 4)
Cvar_FullSet ("maxclients", "4", CVAR_SERVERINFO | CVAR_LATCH);
#ifdef COPYPROTECT
if (!sv.attractloop && !dedicated->value)
Sys_CopyProtect ();
#endif
}
else // non-deathmatch, non-coop is one player
{
Cvar_FullSet ("maxclients", "1", CVAR_SERVERINFO | CVAR_LATCH);
#ifdef COPYPROTECT
if (!sv.attractloop)
Sys_CopyProtect ();
#endif
}
svs.spawncount = rand();
svs.clients = Z_Malloc (sizeof(client_t)*maxclients->value);
svs.num_client_entities = maxclients->value*UPDATE_BACKUP*64;
svs.client_entities = Z_Malloc (sizeof(entity_state_t)*svs.num_client_entities);
// init network stuff
NET_Config ( (maxclients->value > 1) );
// heartbeats will always be sent to the id master
svs.last_heartbeat = -99999; // send immediately
Com_sprintf(idmaster, sizeof(idmaster), "192.246.40.37:%i", PORT_MASTER);
NET_StringToAdr (idmaster, &master_adr[0]);
// init game
SV_InitGameProgs ();
for (i=0 ; i<maxclients->value ; i++)
{
ent = EDICT_NUM(i+1);
ent->s.number = i+1;
svs.clients[i].edict = ent;
memset (&svs.clients[i].lastcmd, 0, sizeof(svs.clients[i].lastcmd));
}
}
示例8: SV_SpawnServer
/*
================
SV_SpawnServer
Change the server to a new map, taking all connected
clients along with it.
================
*/
void SV_SpawnServer (char *server, char *spawnpoint, server_state_t serverstate,
qboolean attractloop, qboolean loadgame)
{
int i;
unsigned checksum;
float cer_public;
float cer_sv_login;
float cer_sv_forcesky;
float cer_guntemp_inc;
float cer_guntemp_dec;
float cer_elim;
float cer_fraglimit;
float cer_timelimit;
if (attractloop)
Cvar_Set("paused", "0");
Com_Printf("------- Server Initialization -------\n");
Com_DPrintf("SpawnServer: %s\n", server);
if (sv.demofile)
fclose(sv.demofile);
svs.spawncount++; // any partially connected client will be restarted
sv.state = ss_dead;
Com_SetServerState(sv.state);
// wipe the entire per-level structure
memset(&sv, 0, sizeof(sv));
svs.realtime = 0;
sv.loadgame = loadgame;
sv.attractloop = attractloop;
// save name for levels that don't set message
strcpy(sv.configstrings[CS_NAME], server);
sprintf(sv.configstrings[CS_AIRACCEL], "%g", sv_airaccelerate->value);
pm_airaccelerate = sv_airaccelerate->value;
SV_ReplicatePhysicsSettings(); // jitmovephysics
sprintf(sv.configstrings[CS_SERVEREVERSION], "Enginever: %g Enginebuild: %d", VERSION, BUILD);
SZ_Init(&sv.multicast, sv.multicast_buf, sizeof(sv.multicast_buf));
strcpy(sv.name, server);
// leave slots at start for clients only
for (i = 0; i < maxclients->value; i++)
{
// needs to reconnect
if (svs.clients[i].state > cs_connected)
svs.clients[i].state = cs_connected;
svs.clients[i].lastframe = -1;
}
sv.time = 1000;
strcpy(sv.name, server);
strcpy(sv.configstrings[CS_NAME], server);
if (serverstate != ss_game)
{
sv.models[1] = CM_LoadMap("", false, &checksum); // no real map
}
else
{
Com_sprintf(sv.configstrings[CS_MODELS + 1], sizeof(sv.configstrings[CS_MODELS + 1]), "maps/%s.bsp", server);
sv.models[1] = CM_LoadMap(sv.configstrings[CS_MODELS + 1], false, &checksum);
}
Com_sprintf(sv.configstrings[CS_MAPCHECKSUM], sizeof(sv.configstrings[CS_MAPCHECKSUM]), "%i", checksum);
// clear physics interaction links
SV_ClearWorld();
for (i = 1; i < CM_NumInlineModels(); i++)
{
Com_sprintf (sv.configstrings[CS_MODELS + 1 + i], sizeof(sv.configstrings[CS_MODELS + 1 + i]), "*%i", i);
sv.models[i + 1] = CM_InlineModel(sv.configstrings[CS_MODELS + 1 + i]);
}
//
// spawn the rest of the entities on the map
//
// precache and static commands can be issued during
// map initialization
sv.state = ss_loading;
Com_SetServerState(sv.state);
//if(!sv.attractloop) // jitdemo -- don't spawn game stuff while demo is playing!
{
//.........这里部分代码省略.........
示例9: SV_Map
/*
======================
SV_Map
the full syntax is:
map [*]<map>$<startspot>+<nextserver>
command from the console or progs.
Map can also be a.cin, .pcx, or .dm2 file
Nextserver is used to allow a cinematic to play, then proceed to
another level:
map tram.cin+jail_e3
======================
*/
void SV_Map (qboolean attractloop, const char *levelstring, qboolean loadgame)
{
char level[MAX_QPATH];
char *ch;
int l;
char spawnpoint[MAX_QPATH];
strcpy(level, levelstring); // jit - copy level string before it gets modified by other commands (since it's a command argument)
sv.loadgame = loadgame;
sv.attractloop = attractloop;
if (sv.state == ss_dead && !sv.loadgame)
SV_InitGame(); // the game is just starting
// if there is a + in the map, set nextserver to the remainder
ch = strstr(level, "+");
if (ch)
{
*ch = 0;
Cvar_Set("nextserver", va("gamemap \"%s\"", ch + 1));
}
else
{
Cvar_Set("nextserver", "");
}
//ZOID special hack for end game screen in coop mode
if (Cvar_VariableValue("coop") && Q_strcaseeq(level, "victory.pcx"))
Cvar_Set("nextserver", "gamemap \"*base1\"");
// if there is a $, use the remainder as a spawnpoint
ch = strstr(level, "$");
if (ch)
{
*ch = 0;
strcpy(spawnpoint, ch + 1);
}
else
{
spawnpoint[0] = 0;
}
// skip the end-of-unit flag if necessary
if (level[0] == '*')
strcpy (level, level+1);
l = strlen(level);
if (l > 4 && Q_streq(level + l - 4, ".cin"))
{
SCR_BeginLoadingPlaque(NULL); // for local system
SV_BroadcastCommand("changing\n");
SV_SpawnServer(level, spawnpoint, ss_cinematic, attractloop, loadgame);
}
else if (l > 4 && Q_streq(level + l - 4, ".dm2"))
{
SCR_BeginLoadingPlaque(NULL); // for local system
SV_BroadcastCommand("changing\n");
SV_SpawnServer(level, spawnpoint, ss_demo, attractloop, loadgame);
}
else if (l > 4 && Q_streq(level + l - 4, ".pcx"))
{
SCR_BeginLoadingPlaque(NULL); // for local system
SV_BroadcastCommand("changing\n");
SV_SpawnServer(level, spawnpoint, ss_pic, attractloop, loadgame);
}
else
{
char changing_cmd[1024];
if (!dedicated->value)
SCR_BeginLoadingPlaque(level); // for local system
Com_sprintf(changing_cmd, sizeof(changing_cmd), "changing \"%s\"\n", level);
SV_BroadcastCommand(changing_cmd);
SV_SendClientMessages();
SV_SpawnServer(level, spawnpoint, ss_game, attractloop, loadgame);
Cbuf_CopyToDefer();
}
SV_BroadcastCommand("reconnect\n");
}
示例10: G_Referee_v
// *** Referee voting ***
int G_Referee_v(gentity_t *ent, unsigned int dwVoteIndex, char *arg, char *arg2, qboolean fRefereeCmd)
{
// Vote request (vote is being initiated)
if (arg)
{
int pid;
if (!vote_allow_referee.integer && ent && !ent->client->sess.referee)
{
G_voteDisableMessage(ent, arg);
return(G_INVALID);
}
if (!ent->client->sess.referee && level.numPlayingClients < 3)
{
G_refPrintf(ent, "Sorry, not enough clients in the game to vote for a referee");
return(G_INVALID);
}
if (ent->client->sess.referee && trap_Argc() == 2)
{
G_playersMessage(ent);
return(G_INVALID);
}
else if (trap_Argc() == 2)
{
pid = ent - g_entities;
}
else if (G_voteDescription(ent, fRefereeCmd, dwVoteIndex))
{
return(G_INVALID);
}
else if ((pid = ClientNumberFromString(ent, arg2)) == -1)
{
return(G_INVALID);
}
if (level.clients[pid].sess.referee)
{
G_refPrintf(ent, "[lof]%s [lon]is already a referee!", level.clients[pid].pers.netname);
return(-1);
}
Com_sprintf(level.voteInfo.vote_value, VOTE_MAXSTRING, "%d", pid);
Com_sprintf(arg2, VOTE_MAXSTRING, "%s", level.clients[pid].pers.netname);
// Vote action (vote has passed)
}
else
{
// Voting in a new referee
gclient_t *cl = &level.clients[atoi(level.voteInfo.vote_value)];
if (cl->pers.connected == CON_DISCONNECTED)
{
AP("print \"Player left before becoming referee\n\"");
}
else
{
cl->sess.referee = RL_REFEREE; // FIXME: Differentiate voted refs from passworded refs
cl->sess.spec_invite = TEAM_AXIS | TEAM_ALLIES;
AP(va("cp \"%s^7 is now a referee\n\"", cl->pers.netname));
ClientUserinfoChanged(atoi(level.voteInfo.vote_value));
}
}
return(G_OK);
}
示例11: Com_sprintf
script_t *LoadScriptFile(const char *filename) {
fileHandle_t h_up, h_patch;
char pathname[MAX_QPATH], pathpatch[MAX_QPATH];
unsigned long inhash = 0;
int inlength, outlength, plength;
char *inbuffer, *outbuffer, *pbuffer;
script_t *script;
if (strlen(basefolder)) {
Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename);
Com_sprintf(pathpatch, sizeof(pathpatch), "%s/%s_patch", basefolder, filename);
} else {
Com_sprintf(pathname, sizeof(pathname), "%s", filename);
Com_sprintf(pathpatch, sizeof(pathpatch), "%s_patch", filename);
}
inlength = botimport.FS_FOpenFileHash(pathname, &h_up, FS_READ, &inhash);
if (!h_up) return NULL;
plength = botimport.FS_FOpenFile(pathpatch, &h_patch, FS_READ);
inbuffer = (char *)GetClearedMemory(inlength + 1);
botimport.FS_Read(inbuffer, inlength, h_up);
botimport.FS_FCloseFile(h_up);
if (h_patch) {
pbuffer = (char *)GetClearedMemory(plength + 1);
botimport.FS_Read(pbuffer, plength, h_patch);
botimport.FS_FCloseFile(h_patch);
Com_Printf("patching menu file %s...\n", pathname);
outlength = MV_MenuPatchFile(inbuffer, inhash, pbuffer, &outbuffer);
if (outlength < 0) {
if (outlength == ERROR_SYNTAX) {
Com_Printf("patching failed: syntax error in patchfile\n");
} else if (outlength == ERROR_HASH) {
Com_Printf("patching skipped: hash mismatch\n");
}
outbuffer = inbuffer;
outlength = inlength;
}
FreeMemory(pbuffer);
// uncomment to dump patched file with _patched suffix; menu_patch
/*
char patchedName[MAX_QPATH];
fileHandle_t patchedFile;
Com_sprintf(patchedName, sizeof(patchedName), "%s_patched", pathname);
botimport.FS_FOpenFile(patchedName, &patchedFile, FS_WRITE);
botimport.FS_Write(outbuffer, outlength, patchedFile);
botimport.FS_FCloseFile(patchedFile);
*/
} else {
outbuffer = inbuffer;
outlength = inlength;
}
script = (script_t *)GetClearedMemory(sizeof(script_t) + outlength + 1);
Com_Memset(script, 0, sizeof(script_t));
strcpy(script->filename, filename);
script->buffer = (char *)script + sizeof(script_t);
script->buffer[outlength] = 0;
script->length = outlength;
script->script_p = script->buffer;
script->lastscript_p = script->buffer;
script->end_p = &script->buffer[outlength];
script->tokenavailable = 0;
script->line = 1;
script->lastline = 1;
SetScriptPunctuations(script, NULL);
Com_Memcpy(script->buffer, outbuffer, outlength);
FreeMemory(outbuffer);
if (outbuffer != inbuffer)
FreeMemory(inbuffer);
script->length = COM_Compress(script->buffer);
return script;
} //end of the function LoadScriptFile
示例12: G_Mute_v
// *** Player Mute ***
int G_Mute_v(gentity_t *ent, unsigned int dwVoteIndex, char *arg, char *arg2, qboolean fRefereeCmd)
{
if (fRefereeCmd)
{
// handled elsewhere
return(G_NOTFOUND);
}
// Vote request (vote is being initiated)
if (arg)
{
int pid;
if (!vote_allow_muting.integer && ent && !ent->client->sess.referee)
{
G_voteDisableMessage(ent, arg);
return(G_INVALID);
}
else if (G_voteDescription(ent, fRefereeCmd, dwVoteIndex))
{
return(G_INVALID);
}
else if ((pid = ClientNumberFromString(ent, arg2)) == -1)
{
return(G_INVALID);
}
if (level.clients[pid].sess.referee)
{
G_refPrintf(ent, "Can't vote to mute referees!");
return(G_INVALID);
}
if (level.clients[pid].sess.muted)
{
G_refPrintf(ent, "Player is already muted!");
return(G_INVALID);
}
Com_sprintf(level.voteInfo.vote_value, VOTE_MAXSTRING, "%d", pid);
Com_sprintf(arg2, VOTE_MAXSTRING, "%s", level.clients[pid].pers.netname);
// Vote action (vote has passed)
}
else
{
int pid = atoi(level.voteInfo.vote_value);
// Mute a player
if (level.clients[pid].sess.referee != RL_RCON)
{
trap_SendServerCommand(pid, va("cpm \"^3You have been muted\""));
level.clients[pid].sess.muted = qtrue;
AP(va("cp \"%s\n^3has been muted!\n\"", level.clients[pid].pers.netname));
ClientUserinfoChanged(pid);
}
else
{
G_Printf("Cannot mute a referee.\n");
}
}
return(G_OK);
}
示例13: G_Unreferee_v
// *** Un-Referee voting ***
int G_Unreferee_v(gentity_t *ent, unsigned int dwVoteIndex, char *arg, char *arg2, qboolean fRefereeCmd)
{
// Vote request (vote is being initiated)
if (arg)
{
int pid;
if (!vote_allow_referee.integer && ent && !ent->client->sess.referee)
{
G_voteDisableMessage(ent, arg);
return(G_INVALID);
}
if (ent->client->sess.referee && trap_Argc() == 2)
{
G_playersMessage(ent);
return(G_INVALID);
}
else if (trap_Argc() == 2)
{
pid = ent - g_entities;
}
else if (G_voteDescription(ent, fRefereeCmd, dwVoteIndex))
{
return(G_INVALID);
}
else if ((pid = ClientNumberFromString(ent, arg2)) == -1)
{
return(G_INVALID);
}
if (level.clients[pid].sess.referee == RL_NONE)
{
G_refPrintf(ent, "[lof]%s [lon]isn't a referee!", level.clients[pid].pers.netname);
return(G_INVALID);
}
if (level.clients[pid].sess.referee == RL_RCON)
{
G_refPrintf(ent, "[lof]%s's [lon]status cannot be removed", level.clients[pid].pers.netname);
return(G_INVALID);
}
if (level.clients[pid].pers.localClient)
{
G_refPrintf(ent, "[lof]%s's [lon]is the Server Host", level.clients[pid].pers.netname);
return(G_INVALID);
}
Com_sprintf(level.voteInfo.vote_value, VOTE_MAXSTRING, "%d", pid);
Com_sprintf(arg2, VOTE_MAXSTRING, "%s", level.clients[pid].pers.netname);
// Vote action (vote has passed)
}
else
{
// Stripping of referee status
gclient_t *cl = &level.clients[atoi(level.voteInfo.vote_value)];
cl->sess.referee = RL_NONE;
cl->sess.spec_invite = 0;
AP(va("cp \"%s^7\nis no longer a referee\n\"", cl->pers.netname));
ClientUserinfoChanged(atoi(level.voteInfo.vote_value));
}
return(G_OK);
}
示例14: CL_GetServerCommand
/*
=======================================================================================================================================
CL_GetServerCommand
Set up argc/argv for the given command.
=======================================================================================================================================
*/
qboolean CL_GetServerCommand(int serverCommandNumber) {
char *s;
char *cmd;
static char bigConfigString[BIG_INFO_STRING];
int argc;
// if we have irretrievably lost a reliable command, drop the connection
if (serverCommandNumber <= clc.serverCommandSequence - MAX_RELIABLE_COMMANDS) {
// when a demo record was started after the client got a whole bunch of reliable commands then the client never got those first
// reliable commands
if (clc.demoplaying) {
return qfalse;
}
Com_Error(ERR_DROP, "CL_GetServerCommand: a reliable command was cycled out");
return qfalse;
}
if (serverCommandNumber > clc.serverCommandSequence) {
Com_Error(ERR_DROP, "CL_GetServerCommand: requested a command not received");
return qfalse;
}
s = clc.serverCommands[serverCommandNumber & (MAX_RELIABLE_COMMANDS - 1)];
clc.lastExecutedServerCommand = serverCommandNumber;
Com_DPrintf("serverCommand: %i : %s\n", serverCommandNumber, s);
rescan:
Cmd_TokenizeString(s);
cmd = Cmd_Argv(0);
argc = Cmd_Argc();
if (!strcmp(cmd, "disconnect")) {
// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=552
// allow server to indicate why they were disconnected
if (argc >= 2) {
Com_Error(ERR_SERVERDISCONNECT, "Server disconnected - %s", Cmd_Argv(1));
} else {
Com_Error(ERR_SERVERDISCONNECT, "Server disconnected");
}
}
if (!strcmp(cmd, "bcs0")) {
Com_sprintf(bigConfigString, BIG_INFO_STRING, "cs %s \"%s", Cmd_Argv(1), Cmd_Argv(2));
return qfalse;
}
if (!strcmp(cmd, "bcs1")) {
s = Cmd_Argv(2);
if (strlen(bigConfigString) + strlen(s) >= BIG_INFO_STRING) {
Com_Error(ERR_DROP, "bcs exceeded BIG_INFO_STRING");
}
strcat(bigConfigString, s);
return qfalse;
}
if (!strcmp(cmd, "bcs2")) {
s = Cmd_Argv(2);
if (strlen(bigConfigString) + strlen(s) + 1 >= BIG_INFO_STRING) {
Com_Error(ERR_DROP, "bcs exceeded BIG_INFO_STRING");
}
strcat(bigConfigString, s);
strcat(bigConfigString, "\"");
s = bigConfigString;
goto rescan;
}
if (!strcmp(cmd, "cs")) {
CL_ConfigstringModified();
// reparse the string, because CL_ConfigstringModified may have done another Cmd_TokenizeString()
Cmd_TokenizeString(s);
return qtrue;
}
if (!strcmp(cmd, "map_restart")) {
// clear notify lines and outgoing commands before passing the restart to the cgame
Con_ClearNotify();
// reparse the string, because Con_ClearNotify() may have done another Cmd_TokenizeString()
Cmd_TokenizeString(s);
Com_Memset(cl.cmds, 0, sizeof(cl.cmds));
return qtrue;
}
// the clientLevelShot command is used during development to generate 128 * 128 screenshots from the intermission
// point of levels for the menu system to use
// we pass it along to the cgame to make appropriate adjustments, but we also clear the console and notify lines here
if (!strcmp(cmd, "clientLevelShot")) {
// don't do it if we aren't running the server locally, otherwise malicious remote servers could overwrite the existing thumbnails
//.........这里部分代码省略.........
示例15: TDM_Disconnected
/*
==============
TDM_Disconnected
==============
A player disconnected, do things.
*/
void TDM_Disconnected (edict_t *ent)
{
qboolean removeTimeout;
removeTimeout = false;
//have to check this right up here since we nuke the teamplayer just below!
if (tdm_match_status == MM_TIMEOUT && level.tdm_timeout_caller && level.tdm_timeout_caller->client == ent)
removeTimeout = true;
//we remove this up here so TDM_LeftTeam doesn't try to resume if we become implicit timeout caller
TDM_RemoveStatsLink (ent);
if (ent->client->pers.team)
{
if (tdm_match_status >= MM_PLAYING && tdm_match_status != MM_SCOREBOARD)
{
//do joincode stuff if a team player disconnects - save all their client info
ent->client->resp.teamplayerinfo->saved_client = gi.TagMalloc (sizeof(gclient_t), TAG_GAME);
*ent->client->resp.teamplayerinfo->saved_client = *ent->client;
ent->client->resp.teamplayerinfo->saved_entity = gi.TagMalloc (sizeof(edict_t), TAG_GAME);
*ent->client->resp.teamplayerinfo->saved_entity = *ent;
if (TDM_Is1V1() && g_1v1_timeout->value > 0)
{
edict_t *ghost;
//may have already been set by a player or previous client disconnect
if (tdm_match_status != MM_TIMEOUT)
{
edict_t *opponent;
//timeout is called implicitly in 1v1 games or the other player would auto win
level.timeout_end_framenum = level.realframenum + SECS_TO_FRAMES(g_1v1_timeout->value);
level.last_tdm_match_status = tdm_match_status;
tdm_match_status = MM_TIMEOUT;
level.tdm_timeout_caller = ent->client->resp.teamplayerinfo;
gi.bprintf (PRINT_CHAT, "%s disconnected and has %s to reconnect.\n", level.tdm_timeout_caller->name, TDM_SecsToString (g_1v1_timeout->value));
//show the opponent their options
opponent = TDM_FindPlayerForTeam (TEAM_A);
if (opponent)
gi.cprintf (opponent, PRINT_HIGH, "Your opponent has disconnected. You can allow them %s to reconnect, or you can force a forfeit by typing 'win' in the console.\n", TDM_SecsToString (g_1v1_timeout->value));
opponent = TDM_FindPlayerForTeam (TEAM_B);
if (opponent)
gi.cprintf (opponent, PRINT_HIGH, "Your opponent has disconnected. You can allow them %s to reconnect, or you can force a forfeit by typing 'win' in the console.\n", TDM_SecsToString (g_1v1_timeout->value));
}
//show a "ghost" player where the player was
ghost = G_Spawn ();
VectorCopy (ent->s.origin, ghost->s.origin);
VectorCopy (ent->s.origin, ghost->old_origin);
VectorCopy (ent->s.angles, ghost->s.angles);
ghost->s.effects = EF_SPHERETRANS;
ghost->s.modelindex = 255;
ghost->s.modelindex2 = 255;
ghost->s.skinnum = ent - g_edicts - 1;
ghost->s.frame = ent->s.frame;
ghost->count = ent->s.number;
ghost->classname = "ghost";
ghost->target_ent = ent;
ghost->enttype = ENT_GHOST;
gi.linkentity (ghost);
}
}
if (removeTimeout)
TDM_ResumeGame ();
TDM_LeftTeam (ent, false);
}
TDM_TeamsChanged ();
if (tdm_match_status == MM_WARMUP && teaminfo[TEAM_SPEC].players == 0 && teaminfo[TEAM_A].players == 0 && teaminfo[TEAM_B].players == 0)
{
if (vote.active)
TDM_RemoveVote ();
//reset the map if it's been running for over 7 days to workaround time precision bugs in the engine, fixes 0000208
if (time (NULL) - level.spawntime > (86400 * 7))
{
char command[256];
Com_sprintf (command, sizeof(command), "gamemap \"%s\"\n", level.mapname);
gi.AddCommandString (command);
}
}
else
TDM_CheckVote ();
//zero for connecting clients on server browsers
//.........这里部分代码省略.........