Debian Codegraph @

code/game/g_svcmds_ext.c

raw
1 //KK-OAX
2 /*
3 ===========================================================================
4 Copyright (C) 1999-2005 Id Software, Inc.
5
6 This file is part of the Open Arena source code.
7 Copied from Tremulous under GPL version 2 including any later version.
8
9 Open Arena source code is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
13
14 Open Arena source code is distributed in the hope that it will be
15 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Open Arena source code; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ===========================================================================
23 */
24
25 #include "g_local.h"
26
27 /*
28 ============
29 Svcmd_status_f
30 Does Server Status from Console
31 ============
32 */
33 void Svcmd_Status_f( void )
34 {
35 int i;
36 gclient_t *cl;
37 char userinfo[ MAX_INFO_STRING ];
38
39 G_Printf( "slot score ping address rate name\n" );
40 G_Printf( "---- ----- ---- ------- ---- ----\n" );
41 for( i = 0, cl = level.clients; i < level.maxclients; i++, cl++ )
42 {
43 if( cl->pers.connected == CON_DISCONNECTED )
44 continue;
45
46 G_Printf( "%-4d ", i );
47 G_Printf( "%-5d ", cl->ps.persistant[ PERS_SCORE ] );
48
49 if( cl->pers.connected == CON_CONNECTING )
50 G_Printf( "CNCT " );
51 else
52 G_Printf( "%-4d ", cl->ps.ping );
53
54 trap_GetUserinfo( i, userinfo, sizeof( userinfo ) );
55 G_Printf( "%-21s ", Info_ValueForKey( userinfo, "ip" ) );
56 G_Printf( "%-8d ", Info_ValueForKey( userinfo, "rate" ) );
57 G_Printf( "%s\n", cl->pers.netname ); // Info_ValueForKey( userinfo, "name" )
58 }
59 }
60
61 /*
62 ============
63 Svcmd_TeamMessage_f
64 Sends a Chat Message to a Team from the Console
65 ============
66 */
67 void Svcmd_TeamMessage_f( void )
68 {
69 char teamNum[ 2 ];
70 const char* prefix;
71 team_t team;
72
73 if( trap_Argc( ) < 3 )
74 {
75 G_Printf( "usage: say_team <team> <message>\n" );
76 return;
77 }
78
79 trap_Argv( 1, teamNum, sizeof( teamNum ) );
80 team = G_TeamFromString( teamNum );
81
82 if( team == TEAM_NUM_TEAMS )
83 {
84 G_Printf( "say_team: invalid team \"%s\"\n", teamNum );
85 return;
86 }
87
88 prefix = BG_TeamName( team );
89 prefix = va( "[%c] ", toupper( *prefix ) );
90
91 G_TeamCommand( team, va( "tchat \"(console): " S_COLOR_CYAN "%s\"", ConcatArgs( 2 ) ) );
92 G_LogPrintf( "sayteam: %sconsole: " S_COLOR_CYAN "%s\n", prefix, ConcatArgs( 2 ) );
93 }
94
95 /*
96 ============
97 Svcmd_CenterPrint_f
98 Does a CenterPrint from the Console
99 ============
100 */
101 void Svcmd_CenterPrint_f( void )
102 {
103 if( trap_Argc( ) < 2 )
104 {
105 G_Printf( "usage: cp <message>\n" );
106 return;
107 }
108
109 trap_SendServerCommand( -1, va( "cp \"%s\"", ConcatArgs( 1 ) ) );
110 }
111 /*
112 ============
113 Svcmd_BannerPrint_f
114 Does a BannerPrint from the Console
115 KK-OAX Commented out in g_svccmds.c, so right now it's useless.
116 ============
117 */
118 void Svcmd_BannerPrint_f( void )
119 {
120 if( trap_Argc( ) < 2 )
121 {
122 G_Printf( "usage: bp <message>\n" );
123 return;
124 }
125
126 trap_SendServerCommand( -1, va( "bp \"%s\"", ConcatArgs( 1 ) ) );
127 }
128 /*
129 ============
130 Svcmd_EjectClient_f
131 Kicks a Client from Console
132 KK-OAX, I'm pretty sure this is also done in the "server" portion
133 of the engine code with "kick," but oh well.
134 ============
135 */
136 void Svcmd_EjectClient_f( void )
137 {
138 char *reason, name[ MAX_STRING_CHARS ];
139
140 if( trap_Argc( ) < 2 )
141 {
142 G_Printf( "usage: eject <player|-1> <reason>\n" );
143 return;
144 }
145
146 trap_Argv( 1, name, sizeof( name ) );
147 reason = ConcatArgs( 2 );
148
149 if( atoi( name ) == -1 )
150 {
151 int i;
152 for( i = 0; i < level.maxclients; i++ )
153 {
154 if( level.clients[ i ].pers.connected == CON_DISCONNECTED )
155 continue;
156 if( level.clients[ i ].pers.localClient )
157 continue;
158 trap_DropClient( i, reason );
159 }
160 }
161 else
162 {
163 gclient_t *cl = ClientForString( name );
164 if( !cl )
165 return;
166 if( cl->pers.localClient )
167 {
168 G_Printf( "eject: cannot eject local clients\n" );
169 return;
170 }
171 trap_DropClient( cl-level.clients, reason );
172 }
173 }
174
175 /*
176 ============
177 Svcmd_DumpUser_f
178 Shows User Info
179 ============
180 */
181 void Svcmd_DumpUser_f( void )
182 {
183 char name[ MAX_STRING_CHARS ], userinfo[ MAX_INFO_STRING ];
184 char key[ BIG_INFO_KEY ], value[ BIG_INFO_VALUE ];
185 const char *info;
186 gclient_t *cl;
187
188 if( trap_Argc( ) != 2 )
189 {
190 G_Printf( "usage: dumpuser <player>\n" );
191 return;
192 }
193
194 trap_Argv( 1, name, sizeof( name ) );
195 cl = ClientForString( name );
196 if( !cl )
197 return;
198
199 trap_GetUserinfo( cl-level.clients, userinfo, sizeof( userinfo ) );
200 info = &userinfo[ 0 ];
201 G_Printf( "userinfo\n--------\n" );
202 //Info_Print( userinfo );
203 while( 1 )
204 {
205 Info_NextPair( &info, key, value );
206 if( !*info )
207 return;
208
209 G_Printf( "%-20s%s\n", key, value );
210 }
211 }
212
213 void Svcmd_Chat_f( void )
214 {
215 trap_SendServerCommand( -1, va( "chat \"%s\"", ConcatArgs( 1 ) ) );
216 G_LogPrintf("chat: %s\n", ConcatArgs( 1 ) );
217 }
218
219 /*
220 =============
221 Svcmd_ListIP_f
222 Dumb Wrapper for the trap_Send command
223 =============
224 */
225 void Svcmd_ListIP_f( void )
226 {
227 trap_SendConsoleCommand( EXEC_NOW, "g_banIPs\n" );
228 }
229
230 /*
231 =============
232 Svcmd_MessageWrapper
233 Dumb wrapper for "a" and "m" and "say"
234 =============
235 */
236 void Svcmd_MessageWrapper( void )
237 {
238 char cmd[ 5 ];
239 trap_Argv( 0, cmd, sizeof( cmd ) );
240 /*if( !Q_stricmp( cmd, "a" ) )
241 Cmd_AdminMessage_f( NULL );
242 else if( !Q_stricmp( cmd, "m" ) )
243 Cmd_PrivateMessage_f( NULL );
244 else*/
245 if( !Q_stricmp( cmd, "say" ) )
246 G_Say( NULL, NULL, SAY_ALL, ConcatArgs( 1 ) );
247 }
248