File: cmdrecycleplayer.c

package info (click to toggle)
xshipwars 1.32-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,176 kB
  • ctags: 6,357
  • sloc: ansic: 157,152; makefile: 226; sh: 75
file content (132 lines) | stat: -rw-r--r-- 3,285 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "swserv.h"

 
/*
 *      Recycles a player object.
 */
int CmdRecyclePlayer(int condescriptor, char *arg)
{
        char name1[XSW_OBJ_NAME_MAX + 80];
        char name2[XSW_OBJ_NAME_MAX + 80];
        
        long object_num;
        long con_object_num;
        
        char sndbuf[CS_DATA_MAX_LEN];
        char stringa[CS_DATA_MAX_LEN];


        /* Error checks. */
        if(arg == NULL)
            return(-1);

        /* Get con_object_num, assumed valid. */
        con_object_num = connection[condescriptor]->object_num;


        /* Copy arg to stringa. */
        strncpy(stringa, arg, CS_DATA_MAX_LEN);
        stringa[CS_DATA_MAX_LEN - 1] = '\0';   
        StringStripSpaces(stringa);


        /* Print usage? */
        if(strlen(stringa) < 1)
        {
            NetSendLiveMessage(condescriptor,
                "Usage: `recycleplayer <player>'"
            );

            return(-1);
        }


        /* Get object_num. */
        object_num = MatchObjectByName(stringa, XSW_OBJ_TYPE_PLAYER);
        if(DBIsObjectGarbage(object_num))
        {
            sprintf(sndbuf,
                "%s: No such player.",
                stringa
            );
            NetSendLiveMessage(condescriptor, sndbuf);

            return(-1);
        }

        /* Cannot recycle player #0 or yourself. */
        if(object_num == 0)
        {
            sprintf(sndbuf,
           "recycleplayer: Permission denied: Cannot recycle %s.",
                DBGetFormalNameStr(object_num)
            );
            NetSendLiveMessage(condescriptor, sndbuf);

            return(-1);
        }
        if(object_num == con_object_num)
        {
            sprintf(sndbuf,
         "recycleplayer: Permission denied: Cannot recycle yourself."
            );
            NetSendLiveMessage(condescriptor, sndbuf);

            return(-1);
        }


        /* Check permissions, allowed to recycle? */
        if(xsw_object[con_object_num]->permission.uid >
           ACCESS_UID_RECYCLEPLAYER
	)
        {
            sprintf(sndbuf,
         "recycleplayer: Requires access level %i: Permission denied.",
                ACCESS_UID_RECYCLEPLAYER
            );
            NetSendLiveMessage(condescriptor, sndbuf);

            return(-1);
        }


        /* ************************************************************* */

        /* Print and log. */
        sprintf(sndbuf,
            "%s: Placed into recycle backup buffer.",
            DBGetFormalNameStr(object_num)
        );
        NetSendLiveMessage(condescriptor, sndbuf);

        strncpy(
	    name1,
	    DBGetFormalNameStr(con_object_num),
	    XSW_OBJ_NAME_MAX + 80
	);
        name1[XSW_OBJ_NAME_MAX + 80 - 1] = '\0';
        strncpy(
	    name2,
	    DBGetFormalNameStr(object_num),
	    XSW_OBJ_NAME_MAX + 80
	);
        name2[XSW_OBJ_NAME_MAX + 80 - 1] = '\0';

        sprintf(
	    stringa,
            "%s: Recycled %s and placed into recycle backup buffer.",
            name1, name2
        );
        if(sysparm.log_general == 1)
            LogAppendLineFormatted(fname.primary_log, stringa);


        /* Recycle object. */
        DBSaveRecycledObject(object_num);
        DBRecycleObject(object_num);
        NetSendRecycleObject(-1, object_num);


        return(0);
}