Crossfire Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CF: patch: shutdown/kick commands
Hi,
the 'shutdown command is used to shutdown the server (not like SIGTERM) ---
it takes you to the "Cleaning up..." message.
The 'kick command was added to support the shutdown -:)
Shutdown, in turn, was added to support our environment, but it might
be useful in other situations, too.
"'kick player" is a DM command. The player is saved.
'shutdown kicks all players if run via DM. If you are not DM, it only works
if you are the only player/socket.
------------------------------ Cut ------------------------------
diff -r -C 5 crossfire-0.93.7/server/c_wiz.c crossfire/server/c_wiz.c
*** crossfire-0.93.7/server/c_wiz.c Tue Jan 6 10:29:23 1998
--- crossfire/server/c_wiz.c Fri Jan 9 16:31:38 1998
***************
*** 89,98 ****
--- 89,146 ----
}
become_follower(ob,params);
return 1;
}
+ int command_kick (object *op, char *params)
+ {
+ struct pl *pl;
+
+ for(pl=first_player;pl!=NULL;pl=pl->next)
+ if((params==NULL || !strcmp(pl->ob->name,params)) && pl->ob!=op)
+ {
+ object *op;
+
+ op=pl->ob;
+ remove_ob(op);
+ op->direction=0;
+ op->contr->count_left=0;
+ new_draw_info_format(NDI_UNIQUE | NDI_ALL, 5, op,
+ "%s is kicked out of the game.",op->name);
+ strcpy(op->contr->killer,"left");
+ check_score(op); /* Always check score */
+ (void)save_player(op,0);
+ play_again(op);
+ op->map->players--;
+ #if MAP_MAXTIMEOUT
+ op->map->timeout = MAP_TIMEOUT(op->map);
+ #endif
+ }
+ return 1;
+ }
+
+ int command_shutdown(object *op, char *params)
+ {
+ struct pl *pl;
+ sockets *s;
+
+ if ((op==NULL && !active_socket->wiz && ((first_socket!=NULL && first_socket->next!=NULL) || (first_player!=NULL))) ||
+ (op!=NULL && !QUERY_FLAG(op,FLAG_WIZ) && ((first_socket!=NULL) || (first_player!=NULL && first_player->next!=NULL))))
+ {
+ new_draw_info(NDI_UNIQUE,0,op,"Sorry, can't shutdown now.");
+ return 1;
+ }
+ command_kick(NULL,NULL);
+ settings.servermode=SERVER_OFF;
+ while (1)
+ {
+ leave(first_player);
+ }
+ /* not reached */
+ return 1;
+ }
+
int command_goto (object *op, char *params)
{
char *name;
object *dummy;
diff -r -C 5 crossfire-0.93.7/server/commands.c crossfire/server/commands.c
*** crossfire-0.93.7/server/commands.c Tue Jan 6 10:29:23 1998
--- crossfire/server/commands.c Fri Jan 9 16:35:35 1998
***************
*** 11,20 ****
--- 11,22 ----
/* Added times to all the commands. However, this was quickly done,
* and probably needs more refinements. All socket and DM commands
* take 0 time.
*/
+ extern int command_shutdown(object *, char *);
+ extern int command_kick(object *, char *);
/*
* Normal game commands
*/
CommArray_s Commands[] = {
***************
*** 80,89 ****
--- 82,92 ----
{"say", command_say, 0.0},
{"scroll", command_scroll, 0.0},
{"shout", command_shout, 0.0},
{"show", command_show, 0.0},
{"showinvicon", command_show_inv_icon, 0.0},
+ {"shutdown", command_shutdown, 0.0},
#ifdef ALLOW_SKILLS
{"skills", command_skills, 0.0}, /* shows player list of skills */
{"use_skill", command_uskill, 0.0},
{"ready_skill", command_rskill, 0.0},
#endif
***************
*** 147,156 ****
--- 150,160 ----
{"name", command_name,0.0},
{"protocol", command_protocol,0.0},
{"quit", command_quit,0.0},
{"set", command_set,0.0},
{"shout", command_shout,0.0},
+ {"shutdown", command_shutdown, 0.0},
{"strings", command_strings,0.0},
{"sync", command_sync,0.0},
{"tell", command_tell,0.0},
{"time", command_time,0.0},
{"unset", command_unset,0.0},
***************
*** 177,186 ****
--- 181,191 ----
{"dumpallobjects", command_dumpallobjects,0.0},
{"dumpmap", command_dumpmap,0.0},
{"free", command_free,0.0},
{"goto", command_goto,0.0},
{"invisible", command_invisible,0.0},
+ {"kick", command_kick, 0.0},
{"nodm", command_nowiz,0.0},
{"nowiz", command_nowiz,0.0},
{"patch", command_patch,0.0},
{"printlos", command_printlos,0.0},
{"remove", command_remove,0.0},
diff -r -C 5 crossfire-0.93.7/server/main.c crossfire/server/main.c
*** crossfire-0.93.7/server/main.c Tue Jan 6 10:29:23 1998
--- crossfire/server/main.c Fri Jan 9 16:40:12 1998
***************
*** 723,775 ****
void leave(player *pl) {
char buf[MAX_BUF];
! /* Lets free this before you close the connection */
! if (pl->pixmaps) free_pixmaps(pl->gdisp, pl->pixmaps);
! if (pl->masks) free_pixmaps(pl->gdisp, pl->masks);
! if (pl->eric_server > 0)
! esrv_remove_player(pl->eric_server);
! else {
! XSync(pl->gdisp, False);
! /* Free all the GCs we made */
! if(pl->gc_root)
! XFreeGC(pl->gdisp, pl->gc_root);
! if(pl->gc_game)
! XFreeGC(pl->gdisp, pl->gc_game);
! if(pl->gc_stats)
! XFreeGC(pl->gdisp, pl->gc_stats);
! if(pl->gc_info)
! XFreeGC(pl->gdisp, pl->gc_info);
! if(pl->gc_inv_text)
! XFreeGC(pl->gdisp, pl->gc_inv_text);
! if(pl->gc_inv_icon)
! XFreeGC(pl->gdisp, pl->gc_inv_icon);
! if(pl->gc_look_text)
! XFreeGC(pl->gdisp, pl->gc_look_text);
! if(pl->gc_look_icon)
! XFreeGC(pl->gdisp, pl->gc_look_icon);
! if(pl->gc_message)
! XFreeGC(pl->gdisp, pl->gc_message);
! if(pl->gc_xpm_floor)
! XFreeGC(pl->gdisp, pl->gc_xpm_floor);
! if(pl->gc_xpm_object)
! XFreeGC(pl->gdisp, pl->gc_xpm_object);
! XDestroyWindow(pl->gdisp,pl->win_game);
! XCloseDisplay(pl->gdisp);
! }
! (void) sprintf(buf,"%s left the game.",pl->name);
! if (pl->ob->map->in_memory==MAP_IN_MEMORY)
pl->ob->map->timeout = MAP_TIMEOUT(pl->ob->map);
! pl->ob->map->players--;
! pl->ob->map=NULL;
! pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
! free_player(pl);
#ifdef SERVER
if(settings.servermode != SERVER_ENABLED)
#endif
if(first_player==NULL) { /* Last player left the game */
clean_tmp_files();
--- 723,778 ----
void leave(player *pl) {
char buf[MAX_BUF];
! if (pl!=NULL)
! {
! /* Lets free this before you close the connection */
! if (pl->pixmaps) free_pixmaps(pl->gdisp, pl->pixmaps);
! if (pl->masks) free_pixmaps(pl->gdisp, pl->masks);
! if (pl->eric_server > 0)
! esrv_remove_player(pl->eric_server);
! else {
! XSync(pl->gdisp, False);
! /* Free all the GCs we made */
! if(pl->gc_root)
! XFreeGC(pl->gdisp, pl->gc_root);
! if(pl->gc_game)
! XFreeGC(pl->gdisp, pl->gc_game);
! if(pl->gc_stats)
! XFreeGC(pl->gdisp, pl->gc_stats);
! if(pl->gc_info)
! XFreeGC(pl->gdisp, pl->gc_info);
! if(pl->gc_inv_text)
! XFreeGC(pl->gdisp, pl->gc_inv_text);
! if(pl->gc_inv_icon)
! XFreeGC(pl->gdisp, pl->gc_inv_icon);
! if(pl->gc_look_text)
! XFreeGC(pl->gdisp, pl->gc_look_text);
! if(pl->gc_look_icon)
! XFreeGC(pl->gdisp, pl->gc_look_icon);
! if(pl->gc_message)
! XFreeGC(pl->gdisp, pl->gc_message);
! if(pl->gc_xpm_floor)
! XFreeGC(pl->gdisp, pl->gc_xpm_floor);
! if(pl->gc_xpm_object)
! XFreeGC(pl->gdisp, pl->gc_xpm_object);
! XDestroyWindow(pl->gdisp,pl->win_game);
! XCloseDisplay(pl->gdisp);
! }
! (void) sprintf(buf,"%s left the game.",pl->name);
! if (pl->ob->map->in_memory==MAP_IN_MEMORY)
pl->ob->map->timeout = MAP_TIMEOUT(pl->ob->map);
! pl->ob->map->players--;
! pl->ob->map=NULL;
! pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
! free_player(pl);
! }
#ifdef SERVER
if(settings.servermode != SERVER_ENABLED)
#endif
if(first_player==NULL) { /* Last player left the game */
clean_tmp_files();
***************
*** 784,794 ****
free_all_god();
/* See what the string data that is out there that hasn't been freed. */
/* LOG(llevDebug, ss_dump_table(0xff));*/
exit(0);
}
! new_draw_info(NDI_UNIQUE | NDI_ALL, 5, NULL, buf);
}
int forbid_play()
{
#if !defined(_IBMR2) && !defined(___IBMR2) && defined(PERM_FILE)
--- 787,797 ----
free_all_god();
/* See what the string data that is out there that hasn't been freed. */
/* LOG(llevDebug, ss_dump_table(0xff));*/
exit(0);
}
! if (pl!=NULL) new_draw_info(NDI_UNIQUE | NDI_ALL, 5, NULL, buf);
}
int forbid_play()
{
#if !defined(_IBMR2) && !defined(___IBMR2) && defined(PERM_FILE)
[to unsubscribe etc., send mail to crossfire-request@ifi.uio.no]