File: cmdrecycle.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 (126 lines) | stat: -rw-r--r-- 3,743 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
#include "swserv.h"
 
 
int CmdRecycle(int condescriptor, char *arg)
{
        char name1[256];
        char name2[256];
        
        long object_num;
        long con_object_num;
        
        char sndbuf[CS_DATA_MAX_LEN];
        
        char stringa[CS_DATA_MAX_LEN];
        
        
        /* Copy arg to stringa. */
        strncpy(stringa, arg, CS_DATA_MAX_LEN);
        stringa[CS_DATA_MAX_LEN - 1] = '\0';   
        StringStripSpaces(stringa);
        
        
        /* If no argument, print usage. */
        if(strlen(stringa) < 1)
        {
            NetSendLiveMessage(condescriptor,
                "Usage: `recycle <object>'"  
            );
            return(-1);
        }

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

 
        /* Get object_num. */ 
        object_num = MatchObjectByName(stringa, -1);
        if(DBIsObjectGarbage(object_num))
        {
            sprintf(sndbuf,
                "%s: No such object.",
                stringa
            );
            NetSendLiveMessage(condescriptor, sndbuf);
        
            return(-1);
        }
        else if(xsw_object[object_num]->type == XSW_OBJ_TYPE_PLAYER)
        {
            sprintf(sndbuf,
                "recycle: Permission denied, use `recycleplayer'."
            );
            NetSendLiveMessage(condescriptor, sndbuf);
        
            return(-1);
        }


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

            return(-1);
        }
        /* If object owned by other, allowed to chown from other? */
        else if((xsw_object[con_object_num]->permission.uid >
                    ACCESS_UID_RECYCLEO) &&
                (xsw_object[object_num]->owner > -1) &&
                (xsw_object[object_num]->owner != con_object_num)
        )
        {
            sprintf(sndbuf,
   "recycle: Requires access level %i: Permission denied, owned by other.",
                ACCESS_UID_RECYCLEO
            );
            NetSendLiveMessage(condescriptor, sndbuf);
            return(-1);
        }
        /* Cannot recycle something with a UID greater than yours. */
        else if(xsw_object[con_object_num]->permission.uid >
                xsw_object[object_num]->permission.uid
        )
        {
            sprintf(sndbuf,
       "recycle: Permission: Target object UID %i exceeds your UID %i.",
                xsw_object[object_num]->permission.uid,
                xsw_object[con_object_num]->permission.uid
            );
            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), 256); 
        name1[255] = '\0';
        strncpy(name2, DBGetFormalNameStr(object_num), 256);
        name2[255] = '\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);
}