#include "copyright.h"
#include "config.h"
#include "mudconf.h"
#include "externs.h"
#include "powers.h"
#include "rbtree.h"
#include "debug.h"
Include dependency graph for comstar.c:
Go to the source code of this file.
Data Structures | |
struct | history_message |
struct | channel |
struct | channel_user |
Defines | |
#define | CHAN_NAME_LEN 50 |
Functions | |
static int | comstar_compare_channel (void *vleft, void *vright, void *arg) |
static int | comstar_compare_channel_user (void *vleft, void *vright, void *arg) |
static int | comstar_compare_alias (void *vleft, void *vright, void *arg) |
static void | comstar_init (void) |
static rbtree | comstar_find_user_channels (dbref player) |
static struct channel * | comstar_find_channel_by_name (char *name) |
static struct channel * | comstar_find_channel_by_user_alias (dbref player, char *alias) |
static int | comstar_add_user_to_channel (char *name, char *alias, dbref player) |
static int | comstar_remove_user_from_channel (char *name, dbref player) |
void | do_createchannel (dbref player, dbref cause, int key, char *channame) |
void | do_destroychannel (dbref player, dbref cause, int key, char *channame) |
void | do_addcom (dbref player, dbref cause, int key, char *arg1, char *arg2) |
void | do_delcom (dbref player, dbref cause, int key, char *arg1) |
Variables | |
static rbtree | channels = NULL |
static rbtree | channel_users = NULL |
#define CHAN_NAME_LEN 50 |
static int comstar_add_user_to_channel | ( | char * | name, | |
char * | alias, | |||
dbref | player | |||
) | [static] |
Definition at line 102 of file comstar.c.
References channel_user::channel, comstar_find_channel_by_name(), comstar_find_user_channels(), rb_exists(), rb_insert(), and channel::users.
Referenced by do_addcom().
00102 { 00103 struct channel *channel = NULL; 00104 struct channel_user *channel_user = NULL; 00105 rbtree uchan = NULL; 00106 00107 channel = comstar_find_channel_by_name(name); 00108 if(!channel) 00109 return 0; 00110 00111 if(rb_exists(channel->users, (void *)player)) 00112 return 0; 00113 00114 uchan = comstar_find_user_channels(player); 00115 if(!uchan) 00116 return 0; 00117 00118 if(rb_exists(uchan, (void *)alias)) 00119 return 0; 00120 00121 channel_user = malloc(sizeof(struct channel_user)); 00122 memset(channel_user, 0, sizeof(struct channel_user)); 00123 00124 channel_user->player = player; 00125 channel_user->alias = strdup(alias); 00126 channel_user->channel = channel; 00127 channel_user->title = strdup(""); 00128 00129 rb_insert(uchan, (void *)channel_user->alias, (void *)channel_user); 00130 rb_insert(channel->users, (void *)channel_user->player, (void *)channel_user); 00131 return 0; 00132 }
static int comstar_compare_alias | ( | void * | vleft, | |
void * | vright, | |||
void * | arg | |||
) | [static] |
Definition at line 59 of file comstar.c.
Referenced by comstar_find_user_channels().
00059 { 00060 char *left = (char *)vleft; 00061 char *right = (char *)vright; 00062 00063 return strcasecmp(left, right); 00064 }
static int comstar_compare_channel | ( | void * | vleft, | |
void * | vright, | |||
void * | arg | |||
) | [static] |
Definition at line 45 of file comstar.c.
Referenced by comstar_init().
00045 { 00046 char *left = (char *)vleft; 00047 char *right= (char *)vright; 00048 00049 return strcmp(left, right); 00050 }
static int comstar_compare_channel_user | ( | void * | vleft, | |
void * | vright, | |||
void * | arg | |||
) | [static] |
Definition at line 52 of file comstar.c.
Referenced by comstar_init(), and do_createchannel().
00052 { 00053 int left = (int) vleft; 00054 int right = (int) vright; 00055 00056 return (left-right); 00057 }
static struct channel* comstar_find_channel_by_name | ( | char * | name | ) | [static] |
Definition at line 82 of file comstar.c.
References channels, and rb_find().
Referenced by comstar_add_user_to_channel(), comstar_remove_user_from_channel(), do_addcom(), do_createchannel(), and do_destroychannel().
00082 { 00083 struct channel *channel = NULL; 00084 00085 channel = rb_find(channels, name); 00086 return channel; 00087 }
Definition at line 89 of file comstar.c.
References channel_user::channel, comstar_find_user_channels(), rb_exists(), and rb_find().
Referenced by do_delcom().
00089 { 00090 rbtree uchan = NULL; 00091 struct channel_user *channel_user = NULL; 00092 struct channel *channel = NULL; 00093 00094 uchan = comstar_find_user_channels(player); 00095 if(!rb_exists(uchan, (void *)alias)) 00096 return NULL; 00097 00098 channel_user = (struct channel_user *)rb_find(uchan, (void *)alias); 00099 return channel_user->channel; 00100 }
Definition at line 71 of file comstar.c.
References channel_users, comstar_compare_alias(), rb_find(), rb_init(), and rb_insert().
Referenced by comstar_add_user_to_channel(), comstar_find_channel_by_user_alias(), and comstar_remove_user_from_channel().
00071 { 00072 rbtree uchan = NULL; 00073 00074 uchan = (rbtree) rb_find(channel_users, (void *)player); 00075 if(!uchan) { 00076 uchan = (rbtree) rb_init(comstar_compare_alias, NULL); 00077 rb_insert(channel_users, (void *)player, uchan); 00078 } 00079 return uchan; 00080 }
static void comstar_init | ( | void | ) | [static] |
Definition at line 66 of file comstar.c.
References channel_users, channels, comstar_compare_channel(), comstar_compare_channel_user(), and rb_init().
00066 { 00067 channels = rb_init(comstar_compare_channel, NULL); 00068 channel_users = rb_init(comstar_compare_channel_user, NULL); 00069 }
static int comstar_remove_user_from_channel | ( | char * | name, | |
dbref | player | |||
) | [static] |
Definition at line 135 of file comstar.c.
References channel_user::alias, channel_user::channel, comstar_find_channel_by_name(), comstar_find_user_channels(), rb_delete(), rb_find(), channel_user::title, and channel::users.
Referenced by do_delcom(), and do_destroychannel().
00135 { 00136 struct channel *channel = NULL; 00137 struct channel_user *channel_user = NULL; 00138 rbtree uchan = NULL; 00139 channel = comstar_find_channel_by_name(name); 00140 if(!channel) 00141 return 0; 00142 00143 uchan = comstar_find_user_channels(player); 00144 if(!uchan) 00145 return 0; 00146 00147 channel_user = (struct channel_user *)rb_find(channel->users, (void *)player); 00148 if(!channel_user) 00149 return 0; 00150 00151 rb_delete(channel->users, (void *)player); 00152 00153 if(!channel_user->alias) 00154 return 0; 00155 rb_delete(uchan, (void *)channel_user->alias); 00156 00157 if(channel_user->title) 00158 free(channel_user->title); 00159 if(channel_user->alias) 00160 free(channel_user->alias); 00161 00162 memset(channel_user, 0, sizeof(struct channel_user)); 00163 free(channel_user); 00164 00165 return 1; 00166 }
Definition at line 235 of file comstar.c.
Referenced by create_player().
00235 { 00236 struct channel *channel = NULL; 00237 if(!mudconf.have_comsys) { 00238 raw_notify(player, "Comsys disabled."); 00239 return; 00240 } 00241 00242 if(!arg1 || !*arg1) { 00243 raw_notify(player, "You need to specify an alias."); 00244 return; 00245 } 00246 00247 if(!arg2 || !*arg2) { 00248 raw_notify(player, "You need to specify a channel."); 00249 return; 00250 } 00251 00252 channel = comstar_find_channel_by_name(arg2); 00253 if(!channel) { 00254 raw_notify(player, "Sorry, Channel does not exist."); 00255 return; 00256 } 00257 00258 if(!comstar_add_user_to_channel(arg2, arg1, player)) { 00259 raw_notify(player, "Operation failed due to invalid argument."); 00260 return; 00261 } 00262 raw_notify(player, "Operation succeeded."); 00263 return; 00264 }
Definition at line 168 of file comstar.c.
00168 { 00169 struct channel *newchannel = NULL; 00170 00171 if(!mudconf.have_comsys) { 00172 raw_notify(player, "Comsys disabled."); 00173 return; 00174 } 00175 if(comstar_find_channel_by_name(channame)) { 00176 notify_printf(player, "Channel %s already exists.", channame); 00177 return; 00178 } 00179 if(!channame || !*channame) { 00180 raw_notify(player, "You must specify a channel to create."); 00181 return; 00182 } 00183 if(!(Comm_All(player))) { 00184 raw_notify(player, "You do not have permission to do that."); 00185 return; 00186 } 00187 if(strlen(channame) > (CHAN_NAME_LEN-1)) { 00188 raw_notify(player, "Name too long."); 00189 return; 00190 } 00191 newchannel = (struct channel *) malloc(sizeof(struct channel)); 00192 memset(newchannel, 0, sizeof(struct channel)); 00193 00194 strncpy(newchannel->name, channame, CHAN_NAME_LEN - 1); 00195 00196 newchannel->type = 127; 00197 newchannel->owner = player; 00198 newchannel->channel_object = NOTHING; 00199 newchannel->users = rb_init(comstar_compare_channel_user, NULL); 00200 notify_printf(player, "Channel %s created.", channame); 00201 }
Definition at line 266 of file comstar.c.
Referenced by do_clearcom().
00266 { 00267 struct channel *channel = NULL; 00268 00269 if(!mudconf.have_comsys) { 00270 raw_notify(player, "Comsys disabled."); 00271 return; 00272 } 00273 if(!arg1 || !*arg1) { 00274 raw_notify(player, "Need an alias to delete."); 00275 return; 00276 } 00277 00278 channel = comstar_find_channel_by_user_alias(player, arg1); 00279 if(!channel) { 00280 raw_notify(player, "Channel alias does not exist."); 00281 return; 00282 } 00283 00284 if(!comstar_remove_user_from_channel(channel->name, player)) { 00285 raw_notify(player, "Operation failed due to invalid argument."); 00286 return; 00287 } 00288 00289 raw_notify(player, "Operation succeeded."); 00290 return; 00291 }
Definition at line 203 of file comstar.c.
00203 { 00204 struct channel *channel = NULL; 00205 00206 if(!mudconf.have_comsys) { 00207 raw_notify(player, "Comsys disabled."); 00208 return; 00209 } 00210 if(!channame || !*channame) { 00211 raw_notify(player, "No argument supplied."); 00212 return; 00213 } 00214 channel = comstar_find_channel_by_name(channame); 00215 00216 if(!channel) { 00217 notify_printf(player, "Could not find channel %s.", channel); 00218 return; 00219 } else if(!(Comm_All(player)) && (player != channel->owner)) { 00220 raw_notify(player, "You do not have permission to do that. "); 00221 return; 00222 } 00223 while(rb_size(channel->users) > 1) { 00224 struct channel_user *channel_user = NULL; 00225 channel_user = rb_search(channel->users, SEARCH_FIRST, NULL); 00226 if(!channel_user) break; 00227 if(!comstar_remove_user_from_channel(channel->name, channel_user->player)) 00228 break; 00229 } 00230 rb_delete(channels, channame); 00231 memset(channel, 0, sizeof(struct channel)); 00232 free(channel); 00233 }
rbtree channel_users = NULL [static] |
Definition at line 43 of file comstar.c.
Referenced by comstar_find_user_channels(), and comstar_init().
Definition at line 42 of file comstar.c.
Referenced by comstar_find_channel_by_name(), comstar_init(), and do_destroychannel().