| 1 |
/*
|
| 2 |
* This program is free software; you can redistribute it and/or
|
| 3 |
* modify it under the terms of the GNU General Public License
|
| 4 |
* as published by the Free Software Foundation; either version 2
|
| 5 |
* of the License, or (at your option) any later version.
|
| 6 |
*
|
| 7 |
* This program is distributed in the hope that it will be useful,
|
| 8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
* GNU General Public License for more details.
|
| 11 |
*
|
| 12 |
* You should have received a copy of the GNU General Public License
|
| 13 |
* along with this program; if not, write to the Free Software
|
| 14 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 15 |
*/
|
| 16 |
#define CLAN_INTERNAL_ACCESS
|
| 17 |
#include "common/setup_before.h"
|
| 18 |
#include <stdio.h>
|
| 19 |
#ifdef HAVE_STDDEF_H
|
| 20 |
# include <stddef.h>
|
| 21 |
#else
|
| 22 |
# ifndef NULL
|
| 23 |
# define NULL ((void *)0)
|
| 24 |
# endif
|
| 25 |
#endif
|
| 26 |
#ifdef STDC_HEADERS
|
| 27 |
# include <stdlib.h>
|
| 28 |
#else
|
| 29 |
# ifdef HAVE_MALLOC_H
|
| 30 |
# include <malloc.h>
|
| 31 |
# endif
|
| 32 |
#endif
|
| 33 |
#ifdef HAVE_STRING_H
|
| 34 |
# include <string.h>
|
| 35 |
#else
|
| 36 |
# ifdef HAVE_STRINGS_H
|
| 37 |
# include <strings.h>
|
| 38 |
# endif
|
| 39 |
#endif
|
| 40 |
#include "compat/strrchr.h"
|
| 41 |
#include "compat/strdup.h"
|
| 42 |
#include "compat/strcasecmp.h"
|
| 43 |
#include "compat/strncasecmp.h"
|
| 44 |
#include "compat/pdir.h"
|
| 45 |
#include <errno.h>
|
| 46 |
#include "compat/strerror.h"
|
| 47 |
#ifdef TIME_WITH_SYS_TIME
|
| 48 |
# include <sys/time.h>
|
| 49 |
# include <time.h>
|
| 50 |
#else
|
| 51 |
# ifdef HAVE_SYS_TIME_H
|
| 52 |
# include <sys/time.h>
|
| 53 |
# else
|
| 54 |
# include <time.h>
|
| 55 |
# endif
|
| 56 |
#endif
|
| 57 |
#ifdef HAVE_SYS_TYPES_H
|
| 58 |
# include <sys/types.h>
|
| 59 |
#endif
|
| 60 |
#include "common/eventlog.h"
|
| 61 |
#include "common/packet.h"
|
| 62 |
#include "common/bnet_protocol.h"
|
| 63 |
#include "common/tag.h"
|
| 64 |
#include "common/util.h"
|
| 65 |
#include "common/bnettime.h"
|
| 66 |
#include "common/eventlog.h"
|
| 67 |
#include "common/list.h"
|
| 68 |
#include "common/proginfo.h"
|
| 69 |
#include "common/bn_type.h"
|
| 70 |
#include "common/xalloc.h"
|
| 71 |
#include "connection.h"
|
| 72 |
#include "anongame.h"
|
| 73 |
#include "prefs.h"
|
| 74 |
#include "friends.h"
|
| 75 |
#include "game.h"
|
| 76 |
#include "clan.h"
|
| 77 |
#include "account.h"
|
| 78 |
#include "channel.h"
|
| 79 |
#include "anongame.h"
|
| 80 |
#include "storage.h"
|
| 81 |
#include "server.h"
|
| 82 |
#include "compat/uint.h"
|
| 83 |
#include "common/setup_after.h"
|
| 84 |
|
| 85 |
static t_list *clanlist_head = NULL;
|
| 86 |
int max_clanid = 0;
|
| 87 |
|
| 88 |
/* callback function for storage use */
|
| 89 |
|
| 90 |
static int _cb_load_clans(void *clan)
|
| 91 |
{
|
| 92 |
if (clanlist_add_clan(clan) < 0)
|
| 93 |
{
|
| 94 |
eventlog(eventlog_level_error, __FUNCTION__, "failed to add clan to clanlist");
|
| 95 |
return -1;
|
| 96 |
}
|
| 97 |
|
| 98 |
if (((t_clan *) clan)->clanid > max_clanid)
|
| 99 |
max_clanid = ((t_clan *) clan)->clanid;
|
| 100 |
return 0;
|
| 101 |
}
|
| 102 |
|
| 103 |
/*
|
| 104 |
** Packet Management
|
| 105 |
*/
|
| 106 |
|
| 107 |
extern int clan_send_packet_to_online_members(t_clan * clan, t_packet * packet)
|
| 108 |
{
|
| 109 |
t_elem *curr;
|
| 110 |
|
| 111 |
if (!clan)
|
| 112 |
{
|
| 113 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 114 |
return -1;
|
| 115 |
}
|
| 116 |
|
| 117 |
if (!packet)
|
| 118 |
{
|
| 119 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL packet");
|
| 120 |
return -1;
|
| 121 |
}
|
| 122 |
|
| 123 |
LIST_TRAVERSE(clan->members, curr)
|
| 124 |
{
|
| 125 |
t_clanmember * member;
|
| 126 |
t_clienttag clienttag;
|
| 127 |
t_connection * conn;
|
| 128 |
|
| 129 |
if (!(member = elem_get_data(curr)))
|
| 130 |
{
|
| 131 |
eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list");
|
| 132 |
continue;
|
| 133 |
}
|
| 134 |
if (!(conn = clanmember_get_conn(member)))
|
| 135 |
continue; // not online
|
| 136 |
|
| 137 |
if (!(clienttag = conn_get_clienttag(conn)))
|
| 138 |
{
|
| 139 |
eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag");
|
| 140 |
continue;
|
| 141 |
}
|
| 142 |
|
| 143 |
if ((clienttag != CLIENTTAG_WARCRAFT3_UINT ) && (clienttag != CLIENTTAG_WAR3XP_UINT))
|
| 144 |
continue; // online but wrong client
|
| 145 |
|
| 146 |
conn_push_outqueue(conn, packet);
|
| 147 |
}
|
| 148 |
|
| 149 |
return 0;
|
| 150 |
}
|
| 151 |
|
| 152 |
extern int clan_send_status_window_on_create(t_clan * clan)
|
| 153 |
{
|
| 154 |
t_packet * rpacket;
|
| 155 |
t_elem *curr;
|
| 156 |
|
| 157 |
if (!(clan))
|
| 158 |
{
|
| 159 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 160 |
return -1;
|
| 161 |
}
|
| 162 |
|
| 163 |
if ((rpacket = packet_create(packet_class_bnet)))
|
| 164 |
{
|
| 165 |
char channelname[10];
|
| 166 |
if (clan->clantag)
|
| 167 |
sprintf(channelname, "Clan %c%c%c%c", (clan->clantag >> 24), (clan->clantag >> 16) & 0xff, (clan->clantag >> 8) & 0xff, clan->clantag & 0xff);
|
| 168 |
else
|
| 169 |
{
|
| 170 |
sprintf(channelname, "Clans");
|
| 171 |
eventlog(eventlog_level_error,__FUNCTION__,"clan has NULL clantag");
|
| 172 |
}
|
| 173 |
|
| 174 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clan_clanack));
|
| 175 |
packet_set_type(rpacket, SERVER_W3XP_CLAN_CLANACK);
|
| 176 |
bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.unknow1, 0);
|
| 177 |
bn_int_set(&rpacket->u.server_w3xp_clan_clanack.clantag, clan->clantag);
|
| 178 |
|
| 179 |
LIST_TRAVERSE(clan->members, curr)
|
| 180 |
{
|
| 181 |
t_clanmember * member;
|
| 182 |
t_clienttag clienttag;
|
| 183 |
t_connection * conn;
|
| 184 |
|
| 185 |
if (!(member = elem_get_data(curr)))
|
| 186 |
{
|
| 187 |
eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list");
|
| 188 |
continue;
|
| 189 |
}
|
| 190 |
if (!(conn = clanmember_get_conn(member)))
|
| 191 |
continue; // not online;
|
| 192 |
|
| 193 |
if (!(clienttag = conn_get_clienttag(conn)))
|
| 194 |
{
|
| 195 |
eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag");
|
| 196 |
continue;
|
| 197 |
}
|
| 198 |
if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT))
|
| 199 |
continue; // online but wrong client
|
| 200 |
|
| 201 |
if (conn_get_channel(conn))
|
| 202 |
{
|
| 203 |
conn_update_w3_playerinfo(conn);
|
| 204 |
channel_set_userflags(conn);
|
| 205 |
if (conn_set_channel(conn, channelname) < 0)
|
| 206 |
conn_set_channel(conn, CHANNEL_NAME_BANNED); /* should not fail */
|
| 207 |
}
|
| 208 |
bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.status, member->status);
|
| 209 |
conn_push_outqueue(conn, rpacket);
|
| 210 |
}
|
| 211 |
packet_del_ref(rpacket);
|
| 212 |
}
|
| 213 |
return 0;
|
| 214 |
}
|
| 215 |
|
| 216 |
extern int clan_close_status_window_on_disband(t_clan * clan)
|
| 217 |
{
|
| 218 |
t_packet * rpacket;
|
| 219 |
t_elem *curr;
|
| 220 |
|
| 221 |
if (!(clan))
|
| 222 |
{
|
| 223 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 224 |
return -1;
|
| 225 |
}
|
| 226 |
|
| 227 |
if ((rpacket = packet_create(packet_class_bnet)))
|
| 228 |
{
|
| 229 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clanquitnotify));
|
| 230 |
packet_set_type(rpacket, SERVER_W3XP_CLANQUITNOTIFY);
|
| 231 |
bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.status, SERVER_W3XP_CLANQUITNOTIFY_STATUS_REMOVED_FROM_CLAN);
|
| 232 |
LIST_TRAVERSE(clan->members, curr)
|
| 233 |
{
|
| 234 |
t_clanmember * member;
|
| 235 |
t_clienttag clienttag;
|
| 236 |
t_connection * conn;
|
| 237 |
|
| 238 |
if (!(member = elem_get_data(curr)))
|
| 239 |
{
|
| 240 |
eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list");
|
| 241 |
continue;
|
| 242 |
}
|
| 243 |
if (!(conn = clanmember_get_conn(member)))
|
| 244 |
continue; // not online;
|
| 245 |
|
| 246 |
if (!(clienttag = conn_get_clienttag(conn)))
|
| 247 |
{
|
| 248 |
eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag");
|
| 249 |
continue;
|
| 250 |
}
|
| 251 |
|
| 252 |
if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT))
|
| 253 |
continue; // online but wrong client
|
| 254 |
|
| 255 |
conn_push_outqueue(conn, rpacket);
|
| 256 |
conn_update_w3_playerinfo(conn);
|
| 257 |
}
|
| 258 |
packet_del_ref(rpacket);
|
| 259 |
}
|
| 260 |
|
| 261 |
|
| 262 |
return 0;
|
| 263 |
}
|
| 264 |
|
| 265 |
extern int clan_send_status_window(t_connection * c)
|
| 266 |
{
|
| 267 |
t_packet * rpacket;
|
| 268 |
t_account *acc;
|
| 269 |
t_clanmember *member;
|
| 270 |
t_clienttag clienttag;
|
| 271 |
t_clan * clan;
|
| 272 |
|
| 273 |
if (!(acc = conn_get_account(c)))
|
| 274 |
return 0;
|
| 275 |
|
| 276 |
if (!(member = account_get_clanmember(acc)))
|
| 277 |
return 0;
|
| 278 |
|
| 279 |
if (!(clan = member->clan))
|
| 280 |
{
|
| 281 |
eventlog(eventlog_level_error,__FUNCTION__,"member has NULL clan");
|
| 282 |
return -1;
|
| 283 |
}
|
| 284 |
|
| 285 |
if (!(clan->clantag))
|
| 286 |
{
|
| 287 |
eventlog(eventlog_level_error,__FUNCTION__,"clan has NULL clantag");
|
| 288 |
return -1;
|
| 289 |
}
|
| 290 |
|
| 291 |
if (!(clienttag = conn_get_clienttag(c)))
|
| 292 |
{
|
| 293 |
eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag");
|
| 294 |
return -1;
|
| 295 |
}
|
| 296 |
|
| 297 |
if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT))
|
| 298 |
return 0;
|
| 299 |
|
| 300 |
if ((rpacket = packet_create(packet_class_bnet)))
|
| 301 |
{
|
| 302 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clan_clanack));
|
| 303 |
packet_set_type(rpacket, SERVER_W3XP_CLAN_CLANACK);
|
| 304 |
bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.unknow1, 0);
|
| 305 |
bn_int_set(&rpacket->u.server_w3xp_clan_clanack.clantag, member->clan->clantag);
|
| 306 |
bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.status, member->status);
|
| 307 |
conn_push_outqueue(c, rpacket);
|
| 308 |
packet_del_ref(rpacket);
|
| 309 |
}
|
| 310 |
return 0;
|
| 311 |
}
|
| 312 |
|
| 313 |
extern int clan_close_status_window(t_connection * c)
|
| 314 |
{
|
| 315 |
t_packet * rpacket;
|
| 316 |
t_clienttag clienttag;
|
| 317 |
|
| 318 |
if (!(clienttag = conn_get_clienttag(c)))
|
| 319 |
{
|
| 320 |
eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag");
|
| 321 |
return -1;
|
| 322 |
}
|
| 323 |
|
| 324 |
if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT))
|
| 325 |
return 0;
|
| 326 |
|
| 327 |
if ((rpacket = packet_create(packet_class_bnet)))
|
| 328 |
{
|
| 329 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clanquitnotify));
|
| 330 |
packet_set_type(rpacket, SERVER_W3XP_CLANQUITNOTIFY);
|
| 331 |
bn_byte_set(&rpacket->u.server_w3xp_clanquitnotify.status, SERVER_W3XP_CLANQUITNOTIFY_STATUS_REMOVED_FROM_CLAN);
|
| 332 |
conn_push_outqueue(c, rpacket);
|
| 333 |
packet_del_ref(rpacket);
|
| 334 |
}
|
| 335 |
return 0;
|
| 336 |
}
|
| 337 |
|
| 338 |
extern int clan_send_memberlist(t_connection * c, t_packet const *const packet)
|
| 339 |
{
|
| 340 |
t_packet * rpacket;
|
| 341 |
t_elem *curr;
|
| 342 |
char const *username;
|
| 343 |
t_clanmember *member;
|
| 344 |
t_clan *clan;
|
| 345 |
t_account *account;
|
| 346 |
int count = 0;
|
| 347 |
char tmpstr[2];
|
| 348 |
const char *append_str;
|
| 349 |
|
| 350 |
if (!(account = conn_get_account(c)))
|
| 351 |
return -1;
|
| 352 |
|
| 353 |
if (!(clan = account_get_clan(account)))
|
| 354 |
return -1;
|
| 355 |
|
| 356 |
if ((rpacket = packet_create(packet_class_bnet)))
|
| 357 |
{
|
| 358 |
t_account * memberacc;
|
| 359 |
|
| 360 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clanmemberlist_reply));
|
| 361 |
packet_set_type(rpacket, SERVER_W3XP_CLANMEMBERLIST_REPLY);
|
| 362 |
bn_int_set(&rpacket->u.server_w3xp_clanmemberlist_reply.count,
|
| 363 |
bn_int_get(packet->u.client_w3xp_clanmemberlist_req.count));
|
| 364 |
LIST_TRAVERSE(clan->members, curr)
|
| 365 |
{
|
| 366 |
if (!(member = elem_get_data(curr)))
|
| 367 |
{
|
| 368 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL element in list");
|
| 369 |
continue;
|
| 370 |
}
|
| 371 |
|
| 372 |
if (!(memberacc = member->memberacc))
|
| 373 |
{
|
| 374 |
eventlog(eventlog_level_error,__FUNCTION__,"member has NULL account");
|
| 375 |
continue;
|
| 376 |
}
|
| 377 |
|
| 378 |
username = account_get_name(memberacc);
|
| 379 |
packet_append_string(rpacket, username);
|
| 380 |
tmpstr[0] = member->status;
|
| 381 |
append_str = clanmember_get_online_status(member, &tmpstr[1]);
|
| 382 |
packet_append_data(rpacket, tmpstr, 2);
|
| 383 |
if (append_str)
|
| 384 |
packet_append_string(rpacket, append_str);
|
| 385 |
else
|
| 386 |
packet_append_string(rpacket, "");
|
| 387 |
count++;
|
| 388 |
}
|
| 389 |
bn_byte_set(&rpacket->u.server_w3xp_clanmemberlist_reply.member_count, count);
|
| 390 |
conn_push_outqueue(c, rpacket);
|
| 391 |
packet_del_ref(rpacket);
|
| 392 |
return 0;
|
| 393 |
}
|
| 394 |
|
| 395 |
return -1;
|
| 396 |
}
|
| 397 |
|
| 398 |
extern int clan_save_motd_chg(t_connection * c, t_packet const *const packet)
|
| 399 |
{
|
| 400 |
t_account *account;
|
| 401 |
char const *motd;
|
| 402 |
int offset;
|
| 403 |
t_clan *clan;
|
| 404 |
|
| 405 |
if ((account = conn_get_account(c)) == NULL)
|
| 406 |
return -1;
|
| 407 |
if ((clan = account_get_clan(account)) == NULL)
|
| 408 |
return -1;
|
| 409 |
offset = sizeof(packet->u.client_w3xp_clan_motdchg);
|
| 410 |
motd = packet_get_str_const(packet, offset, 25);
|
| 411 |
eventlog(eventlog_level_trace, __FUNCTION__, "[%d] got W3XP_CLAN_MOTDCHG packet : %s", conn_get_socket(c), motd);
|
| 412 |
if (clan_set_motd(clan, motd) != 0)
|
| 413 |
{
|
| 414 |
eventlog(eventlog_level_error, __FUNCTION__, "Failed to set clan motd.");
|
| 415 |
return -1;
|
| 416 |
}
|
| 417 |
clan->modified = 1;
|
| 418 |
return 0;
|
| 419 |
}
|
| 420 |
|
| 421 |
|
| 422 |
extern int clan_send_motd_reply(t_connection * c, t_packet const *const packet)
|
| 423 |
{
|
| 424 |
t_packet * rpacket;
|
| 425 |
t_account *account;
|
| 426 |
t_clan *clan;
|
| 427 |
|
| 428 |
if ((account = conn_get_account(c)) == NULL)
|
| 429 |
return -1;
|
| 430 |
if ((clan = account_get_clan(account)) == NULL)
|
| 431 |
return -1;
|
| 432 |
if (clan->clan_motd == NULL)
|
| 433 |
{
|
| 434 |
eventlog(eventlog_level_error, __FUNCTION__, "Failed to get clan motd.");
|
| 435 |
return -1;
|
| 436 |
}
|
| 437 |
if ((rpacket = packet_create(packet_class_bnet)))
|
| 438 |
{
|
| 439 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clan_motdreply));
|
| 440 |
packet_set_type(rpacket, SERVER_W3XP_CLAN_MOTDREPLY);
|
| 441 |
bn_int_set(&rpacket->u.server_w3xp_clan_motdreply.count, bn_int_get(packet->u.client_w3xp_clan_motdreq.count));
|
| 442 |
bn_int_set(&rpacket->u.server_w3xp_clan_motdreply.unknow1, SERVER_W3XP_CLAN_MOTDREPLY_UNKNOW1);
|
| 443 |
packet_append_string(rpacket, clan->clan_motd);
|
| 444 |
conn_push_outqueue(c, rpacket);
|
| 445 |
packet_del_ref(rpacket);
|
| 446 |
}
|
| 447 |
|
| 448 |
return 0;
|
| 449 |
}
|
| 450 |
|
| 451 |
/*
|
| 452 |
** String / Function Management
|
| 453 |
*/
|
| 454 |
|
| 455 |
extern int clan_get_possible_member(t_connection * c, t_packet const *const packet)
|
| 456 |
{
|
| 457 |
t_packet * rpacket;
|
| 458 |
t_channel *channel;
|
| 459 |
t_connection *conn;
|
| 460 |
char const *username;
|
| 461 |
t_account * account;
|
| 462 |
|
| 463 |
int friend_count = 0;
|
| 464 |
int clantag;
|
| 465 |
clantag = bn_int_get(packet->u.client_w3xp_clan_createreq.clantag);
|
| 466 |
if ((rpacket = packet_create(packet_class_bnet)) == NULL)
|
| 467 |
{
|
| 468 |
return -1;
|
| 469 |
}
|
| 470 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clan_createreply));
|
| 471 |
packet_set_type(rpacket, SERVER_W3XP_CLAN_CREATEREPLY);
|
| 472 |
bn_int_set(&rpacket->u.server_w3xp_clan_createreply.count, bn_int_get(packet->u.client_w3xp_clan_createreq.count));
|
| 473 |
if (clanlist_find_clan_by_clantag(clantag) != NULL)
|
| 474 |
{
|
| 475 |
bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.check_result, SERVER_W3XP_CLAN_CREATEREPLY_CHECK_ALLREADY_IN_USE);
|
| 476 |
bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.friend_count, 0);
|
| 477 |
conn_push_outqueue(c, rpacket);
|
| 478 |
packet_del_ref(rpacket);
|
| 479 |
return 0;
|
| 480 |
}
|
| 481 |
if ((account = conn_get_account(c)) && (account_get_clan(account) != NULL || account_get_creating_clan(account) != NULL))
|
| 482 |
{
|
| 483 |
bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.check_result, SERVER_W3XP_CLAN_CREATEREPLY_CHECK_EXCEPTION);
|
| 484 |
bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.friend_count, 0);
|
| 485 |
conn_push_outqueue(c, rpacket);
|
| 486 |
packet_del_ref(rpacket);
|
| 487 |
return 0;
|
| 488 |
}
|
| 489 |
bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.check_result, SERVER_W3XP_CLAN_CREATEREPLY_CHECK_OK);
|
| 490 |
channel = conn_get_channel(c);
|
| 491 |
if (channel_get_permanent(channel))
|
| 492 |
{
|
| 493 |
/* If not in a private channel, retreive number of mutual friend connected */
|
| 494 |
t_list *flist = account_get_friends(conn_get_account(c));
|
| 495 |
t_elem const *curr;
|
| 496 |
t_friend *fr;
|
| 497 |
|
| 498 |
LIST_TRAVERSE_CONST(flist, curr)
|
| 499 |
{
|
| 500 |
if ((fr = elem_get_data(curr)) != NULL)
|
| 501 |
{
|
| 502 |
t_account *fr_acc = friend_get_account(fr);
|
| 503 |
t_clienttag clienttag;
|
| 504 |
if (fr->mutual
|
| 505 |
&& ((conn = connlist_find_connection_by_account(fr_acc)) != NULL)
|
| 506 |
&& (conn_get_channel(conn) == channel)
|
| 507 |
&& (!account_get_clan(fr_acc))
|
| 508 |
&& (!account_get_creating_clan(fr_acc))
|
| 509 |
&& (clienttag = conn_get_clienttag(conn))
|
| 510 |
&& ((clienttag == CLIENTTAG_WAR3XP_UINT) || (clienttag == CLIENTTAG_WARCRAFT3_UINT))
|
| 511 |
&& (username = account_get_name(fr_acc)))
|
| 512 |
{
|
| 513 |
friend_count++;
|
| 514 |
packet_append_string(rpacket, username);
|
| 515 |
}
|
| 516 |
}
|
| 517 |
}
|
| 518 |
} else
|
| 519 |
{
|
| 520 |
/* If in a private channel, retreive all users in the channel */
|
| 521 |
for (conn = channel_get_first(channel); conn; conn = channel_get_next())
|
| 522 |
{
|
| 523 |
if ((conn != c) && (username = conn_get_username(conn)))
|
| 524 |
{
|
| 525 |
friend_count++;
|
| 526 |
packet_append_string(rpacket, username);
|
| 527 |
}
|
| 528 |
}
|
| 529 |
}
|
| 530 |
bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.friend_count, friend_count);
|
| 531 |
conn_push_outqueue(c, rpacket);
|
| 532 |
packet_del_ref(rpacket);
|
| 533 |
|
| 534 |
return 0;
|
| 535 |
}
|
| 536 |
|
| 537 |
extern int clanmember_on_change_status(t_clanmember * member)
|
| 538 |
{
|
| 539 |
t_packet * rpacket;
|
| 540 |
if (member == NULL)
|
| 541 |
{
|
| 542 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 543 |
return -1;
|
| 544 |
}
|
| 545 |
if (member->clan == NULL)
|
| 546 |
{
|
| 547 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 548 |
return -1;
|
| 549 |
}
|
| 550 |
if ((rpacket = packet_create(packet_class_bnet)) != NULL)
|
| 551 |
{
|
| 552 |
char tmpstr[2];
|
| 553 |
const char *append_str;
|
| 554 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clanmemberupdate));
|
| 555 |
packet_set_type(rpacket, SERVER_W3XP_CLANMEMBERUPDATE);
|
| 556 |
packet_append_string(rpacket, account_get_name(member->memberacc));
|
| 557 |
tmpstr[0] = member->status;
|
| 558 |
append_str = clanmember_get_online_status(member, &tmpstr[1]);
|
| 559 |
packet_append_data(rpacket, tmpstr, 2);
|
| 560 |
if (append_str)
|
| 561 |
packet_append_string(rpacket, append_str);
|
| 562 |
else
|
| 563 |
packet_append_string(rpacket, "");
|
| 564 |
clan_send_packet_to_online_members(member->clan, rpacket);
|
| 565 |
packet_del_ref(rpacket);
|
| 566 |
}
|
| 567 |
return 0;
|
| 568 |
}
|
| 569 |
|
| 570 |
extern int clanmember_on_change_status_by_connection(t_connection * conn)
|
| 571 |
{
|
| 572 |
t_packet * rpacket;
|
| 573 |
t_account *acc;
|
| 574 |
t_clanmember *member;
|
| 575 |
if (!(conn))
|
| 576 |
{
|
| 577 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL conn");
|
| 578 |
return -1;
|
| 579 |
}
|
| 580 |
if ((acc = conn_get_account(conn)) == NULL)
|
| 581 |
return -1;
|
| 582 |
if ((member = account_get_clanmember(acc)) == NULL)
|
| 583 |
return -1;
|
| 584 |
if (member->clan == NULL)
|
| 585 |
return -1;
|
| 586 |
if ((rpacket = packet_create(packet_class_bnet)) != NULL)
|
| 587 |
{
|
| 588 |
char tmpstr[2];
|
| 589 |
const char *append_str;
|
| 590 |
packet_set_size(rpacket, sizeof(t_server_w3xp_clanmemberupdate));
|
| 591 |
packet_set_type(rpacket, SERVER_W3XP_CLANMEMBERUPDATE);
|
| 592 |
packet_append_string(rpacket, account_get_name(acc));
|
| 593 |
tmpstr[0] = member->status;
|
| 594 |
append_str = clanmember_get_online_status_by_connection(conn, &tmpstr[1]);
|
| 595 |
packet_append_data(rpacket, tmpstr, 2);
|
| 596 |
if (append_str)
|
| 597 |
packet_append_string(rpacket, append_str);
|
| 598 |
else
|
| 599 |
packet_append_string(rpacket, "");
|
| 600 |
clan_send_packet_to_online_members(member->clan, rpacket);
|
| 601 |
packet_del_ref(rpacket);
|
| 602 |
}
|
| 603 |
return 0;
|
| 604 |
}
|
| 605 |
|
| 606 |
extern int clan_unload_members(t_clan * clan)
|
| 607 |
{
|
| 608 |
t_elem *curr;
|
| 609 |
t_clanmember *member;
|
| 610 |
|
| 611 |
if (clan->members)
|
| 612 |
{
|
| 613 |
LIST_TRAVERSE(clan->members, curr)
|
| 614 |
{
|
| 615 |
if (!(member = elem_get_data(curr)))
|
| 616 |
{
|
| 617 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
|
| 618 |
continue;
|
| 619 |
}
|
| 620 |
list_remove_elem(clan->members, &curr);
|
| 621 |
xfree((void *) member);
|
| 622 |
}
|
| 623 |
|
| 624 |
if (list_destroy(clan->members) < 0)
|
| 625 |
return -1;
|
| 626 |
|
| 627 |
clan->members = NULL;
|
| 628 |
}
|
| 629 |
|
| 630 |
return 0;
|
| 631 |
}
|
| 632 |
|
| 633 |
extern int clan_remove_all_members(t_clan * clan)
|
| 634 |
{
|
| 635 |
t_elem *curr;
|
| 636 |
t_clanmember *member;
|
| 637 |
|
| 638 |
if (clan->members)
|
| 639 |
{
|
| 640 |
LIST_TRAVERSE(clan->members, curr)
|
| 641 |
{
|
| 642 |
if (!(member = elem_get_data(curr)))
|
| 643 |
{
|
| 644 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
|
| 645 |
continue;
|
| 646 |
}
|
| 647 |
if (member->memberacc != NULL)
|
| 648 |
account_set_clanmember(member->memberacc, NULL);
|
| 649 |
list_remove_elem(clan->members, &curr);
|
| 650 |
xfree((void *) member);
|
| 651 |
}
|
| 652 |
|
| 653 |
if (list_destroy(clan->members) < 0)
|
| 654 |
return -1;
|
| 655 |
|
| 656 |
clan->members = NULL;
|
| 657 |
}
|
| 658 |
|
| 659 |
return 0;
|
| 660 |
}
|
| 661 |
|
| 662 |
extern int clanlist_remove_clan(t_clan * clan)
|
| 663 |
{
|
| 664 |
t_elem * elem;
|
| 665 |
if (clan == NULL)
|
| 666 |
{
|
| 667 |
eventlog(eventlog_level_error, __FUNCTION__, "get NULL clan");
|
| 668 |
return -1;
|
| 669 |
}
|
| 670 |
if (list_remove_data(clanlist_head, clan, &elem) < 0)
|
| 671 |
{
|
| 672 |
eventlog(eventlog_level_error, __FUNCTION__, "could not delete clan entry");
|
| 673 |
return -1;
|
| 674 |
}
|
| 675 |
return 0;
|
| 676 |
}
|
| 677 |
|
| 678 |
extern int clan_remove(int clantag)
|
| 679 |
{
|
| 680 |
return storage->remove_clan(clantag);
|
| 681 |
}
|
| 682 |
|
| 683 |
extern int clan_save(t_clan * clan)
|
| 684 |
{
|
| 685 |
if (clan->created <= 0)
|
| 686 |
{
|
| 687 |
if (now - clan->creation_time > 120)
|
| 688 |
{
|
| 689 |
clanlist_remove_clan(clan);
|
| 690 |
clan_destroy(clan);
|
| 691 |
}
|
| 692 |
return 0;
|
| 693 |
}
|
| 694 |
|
| 695 |
storage->write_clan(clan);
|
| 696 |
|
| 697 |
clan->modified = 0;
|
| 698 |
|
| 699 |
return 0;
|
| 700 |
}
|
| 701 |
|
| 702 |
extern t_list *clanlist(void)
|
| 703 |
{
|
| 704 |
return clanlist_head;
|
| 705 |
}
|
| 706 |
|
| 707 |
extern int clanlist_add_clan(t_clan * clan)
|
| 708 |
{
|
| 709 |
if (!(clan))
|
| 710 |
{
|
| 711 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 712 |
return -1;
|
| 713 |
}
|
| 714 |
|
| 715 |
if (!(clan->clanid))
|
| 716 |
clan->clanid = ++max_clanid;
|
| 717 |
|
| 718 |
list_append_data(clanlist_head, clan);
|
| 719 |
|
| 720 |
return clan->clanid;
|
| 721 |
}
|
| 722 |
|
| 723 |
int clanlist_load(void)
|
| 724 |
{
|
| 725 |
// make sure to unload previous clanlist before loading again
|
| 726 |
if (clanlist_head)
|
| 727 |
clanlist_unload();
|
| 728 |
|
| 729 |
clanlist_head = list_create();
|
| 730 |
|
| 731 |
storage->load_clans(_cb_load_clans);
|
| 732 |
|
| 733 |
return 0;
|
| 734 |
}
|
| 735 |
|
| 736 |
extern int clanlist_save(void)
|
| 737 |
{
|
| 738 |
t_elem *curr;
|
| 739 |
t_clan *clan;
|
| 740 |
|
| 741 |
if (clanlist_head)
|
| 742 |
{
|
| 743 |
LIST_TRAVERSE(clanlist_head, curr)
|
| 744 |
{
|
| 745 |
if (!(clan = elem_get_data(curr)))
|
| 746 |
{
|
| 747 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
|
| 748 |
continue;
|
| 749 |
}
|
| 750 |
if (clan->modified)
|
| 751 |
clan_save(clan);
|
| 752 |
}
|
| 753 |
|
| 754 |
}
|
| 755 |
|
| 756 |
return 0;
|
| 757 |
}
|
| 758 |
|
| 759 |
extern int clanlist_unload(void)
|
| 760 |
{
|
| 761 |
t_elem *curr;
|
| 762 |
t_clan *clan;
|
| 763 |
|
| 764 |
if (clanlist_head)
|
| 765 |
{
|
| 766 |
LIST_TRAVERSE(clanlist_head, curr)
|
| 767 |
{
|
| 768 |
if (!(clan = elem_get_data(curr)))
|
| 769 |
{
|
| 770 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
|
| 771 |
continue;
|
| 772 |
}
|
| 773 |
if (clan->clanname)
|
| 774 |
xfree((void *) clan->clanname);
|
| 775 |
if (clan->clan_motd)
|
| 776 |
xfree((void *) clan->clan_motd);
|
| 777 |
clan_unload_members(clan);
|
| 778 |
xfree((void *) clan);
|
| 779 |
list_remove_elem(clanlist_head, &curr);
|
| 780 |
}
|
| 781 |
|
| 782 |
if (list_destroy(clanlist_head) < 0)
|
| 783 |
return -1;
|
| 784 |
|
| 785 |
clanlist_head = NULL;
|
| 786 |
}
|
| 787 |
|
| 788 |
return 0;
|
| 789 |
}
|
| 790 |
|
| 791 |
extern t_clan *clanlist_find_clan_by_clanid(int cid)
|
| 792 |
{
|
| 793 |
t_elem *curr;
|
| 794 |
t_clan *clan;
|
| 795 |
|
| 796 |
if (clanlist_head)
|
| 797 |
{
|
| 798 |
LIST_TRAVERSE(clanlist_head, curr)
|
| 799 |
{
|
| 800 |
if (!(clan = elem_get_data(curr)))
|
| 801 |
{
|
| 802 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
|
| 803 |
continue;
|
| 804 |
}
|
| 805 |
eventlog(eventlog_level_error, __FUNCTION__, "trace %d", clan->clanid);
|
| 806 |
if (clan->created && (clan->clanid == cid))
|
| 807 |
return clan;
|
| 808 |
}
|
| 809 |
|
| 810 |
}
|
| 811 |
|
| 812 |
return NULL;
|
| 813 |
}
|
| 814 |
|
| 815 |
extern t_clan *clanlist_find_clan_by_clantag(int clantag)
|
| 816 |
{
|
| 817 |
t_elem *curr;
|
| 818 |
t_clan *clan;
|
| 819 |
|
| 820 |
if (clantag == 0)
|
| 821 |
return NULL;
|
| 822 |
if (clanlist_head)
|
| 823 |
{
|
| 824 |
LIST_TRAVERSE(clanlist_head, curr)
|
| 825 |
{
|
| 826 |
if (!(clan = elem_get_data(curr)))
|
| 827 |
{
|
| 828 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
|
| 829 |
continue;
|
| 830 |
}
|
| 831 |
if (clan->created && (clan->clantag == clantag))
|
| 832 |
return clan;
|
| 833 |
}
|
| 834 |
|
| 835 |
}
|
| 836 |
|
| 837 |
return NULL;
|
| 838 |
}
|
| 839 |
|
| 840 |
extern t_clanmember *clan_find_member(t_clan * clan, t_account * memberacc)
|
| 841 |
{
|
| 842 |
t_clanmember *member;
|
| 843 |
t_elem *curr;
|
| 844 |
if (!(clan))
|
| 845 |
{
|
| 846 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 847 |
return NULL;
|
| 848 |
}
|
| 849 |
if (!(clan->members))
|
| 850 |
{
|
| 851 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL clan->members");
|
| 852 |
return NULL;
|
| 853 |
}
|
| 854 |
LIST_TRAVERSE(clan->members, curr)
|
| 855 |
{
|
| 856 |
if (!(member = elem_get_data(curr)))
|
| 857 |
{
|
| 858 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL element in list");
|
| 859 |
return NULL;
|
| 860 |
}
|
| 861 |
if (member->memberacc == memberacc)
|
| 862 |
return member;
|
| 863 |
}
|
| 864 |
|
| 865 |
return NULL;
|
| 866 |
}
|
| 867 |
|
| 868 |
extern t_clanmember *clan_find_member_by_name(t_clan * clan, char const *membername)
|
| 869 |
{
|
| 870 |
t_clanmember *member;
|
| 871 |
t_elem *curr;
|
| 872 |
if (!(clan))
|
| 873 |
{
|
| 874 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 875 |
return NULL;
|
| 876 |
}
|
| 877 |
if (!(clan->members))
|
| 878 |
{
|
| 879 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL clan->members");
|
| 880 |
return NULL;
|
| 881 |
}
|
| 882 |
LIST_TRAVERSE(clan->members, curr)
|
| 883 |
{
|
| 884 |
if (!(member = elem_get_data(curr)))
|
| 885 |
{
|
| 886 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL element in list");
|
| 887 |
return NULL;
|
| 888 |
}
|
| 889 |
if (strcasecmp(account_get_name(member->memberacc), membername) == 0)
|
| 890 |
return member;
|
| 891 |
}
|
| 892 |
|
| 893 |
return NULL;
|
| 894 |
}
|
| 895 |
|
| 896 |
extern t_clanmember *clan_find_member_by_uid(t_clan * clan, unsigned int memberuid)
|
| 897 |
{
|
| 898 |
t_clanmember *member;
|
| 899 |
t_elem *curr;
|
| 900 |
if (!(clan))
|
| 901 |
{
|
| 902 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 903 |
return NULL;
|
| 904 |
}
|
| 905 |
if (!(clan->members))
|
| 906 |
{
|
| 907 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL clan->members");
|
| 908 |
return NULL;
|
| 909 |
}
|
| 910 |
LIST_TRAVERSE(clan->members, curr)
|
| 911 |
{
|
| 912 |
if (!(member = elem_get_data(curr)))
|
| 913 |
{
|
| 914 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL element in list");
|
| 915 |
return NULL;
|
| 916 |
}
|
| 917 |
if (account_get_uid(member->memberacc) == memberuid)
|
| 918 |
return member;
|
| 919 |
}
|
| 920 |
|
| 921 |
return NULL;
|
| 922 |
}
|
| 923 |
|
| 924 |
extern t_account *clanmember_get_account(t_clanmember * member)
|
| 925 |
{
|
| 926 |
if (!(member))
|
| 927 |
{
|
| 928 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 929 |
return NULL;
|
| 930 |
}
|
| 931 |
|
| 932 |
return (t_account *) member->memberacc;
|
| 933 |
}
|
| 934 |
|
| 935 |
extern int clanmember_set_account(t_clanmember * member, t_account * memberacc)
|
| 936 |
{
|
| 937 |
if (!(member))
|
| 938 |
{
|
| 939 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 940 |
return -1;
|
| 941 |
}
|
| 942 |
|
| 943 |
member->memberacc = memberacc;
|
| 944 |
return 0;
|
| 945 |
}
|
| 946 |
|
| 947 |
extern t_connection *clanmember_get_conn(t_clanmember * member)
|
| 948 |
{
|
| 949 |
t_account * account;
|
| 950 |
|
| 951 |
if (!(member))
|
| 952 |
{
|
| 953 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 954 |
return NULL;
|
| 955 |
}
|
| 956 |
|
| 957 |
if (!(account = member->memberacc))
|
| 958 |
{
|
| 959 |
eventlog(eventlog_level_error,__FUNCTION__,"member as NULL account");
|
| 960 |
return NULL;
|
| 961 |
}
|
| 962 |
|
| 963 |
return account_get_conn(account);
|
| 964 |
}
|
| 965 |
|
| 966 |
extern char clanmember_get_status(t_clanmember * member)
|
| 967 |
{
|
| 968 |
if (!(member))
|
| 969 |
{
|
| 970 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 971 |
return 0;
|
| 972 |
}
|
| 973 |
|
| 974 |
if ((member->status == CLAN_NEW) && (now - member->join_time > prefs_get_clan_newer_time() * 3600))
|
| 975 |
{
|
| 976 |
member->status = CLAN_PEON;
|
| 977 |
member->clan->modified = 1;
|
| 978 |
#ifdef WITH_SQL
|
| 979 |
member->modified = 1;
|
| 980 |
#endif
|
| 981 |
}
|
| 982 |
|
| 983 |
return member->status;
|
| 984 |
}
|
| 985 |
|
| 986 |
extern int clanmember_set_status(t_clanmember * member, char status)
|
| 987 |
{
|
| 988 |
if (!(member))
|
| 989 |
{
|
| 990 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 991 |
return -1;
|
| 992 |
}
|
| 993 |
|
| 994 |
if (member->status != status)
|
| 995 |
{
|
| 996 |
member->status = status;
|
| 997 |
member->clan->modified = 1;
|
| 998 |
#ifdef WITH_SQL
|
| 999 |
member->modified = 1;
|
| 1000 |
#endif
|
| 1001 |
}
|
| 1002 |
return 0;
|
| 1003 |
}
|
| 1004 |
|
| 1005 |
extern time_t clanmember_get_join_time(t_clanmember * member)
|
| 1006 |
{
|
| 1007 |
if (!(member))
|
| 1008 |
{
|
| 1009 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 1010 |
return 0;
|
| 1011 |
}
|
| 1012 |
|
| 1013 |
return member->join_time;
|
| 1014 |
}
|
| 1015 |
|
| 1016 |
extern t_clan *clanmember_get_clan(t_clanmember * member)
|
| 1017 |
{
|
| 1018 |
if (!(member))
|
| 1019 |
{
|
| 1020 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanmember");
|
| 1021 |
return 0;
|
| 1022 |
}
|
| 1023 |
|
| 1024 |
return member->clan;
|
| 1025 |
}
|
| 1026 |
|
| 1027 |
extern const char *clanmember_get_online_status(t_clanmember * member, char *status)
|
| 1028 |
{
|
| 1029 |
return clanmember_get_online_status_by_connection(clanmember_get_conn(member), status);
|
| 1030 |
}
|
| 1031 |
|
| 1032 |
extern const char *clanmember_get_online_status_by_connection(t_connection * conn, char *status)
|
| 1033 |
{
|
| 1034 |
if (conn && (conn_get_state(conn)!=conn_state_empty))
|
| 1035 |
{
|
| 1036 |
t_game *game;
|
| 1037 |
t_channel *channel;
|
| 1038 |
if ((game = conn_get_game(conn)) != NULL)
|
| 1039 |
{
|
| 1040 |
if (game_get_flag(game) == game_flag_private)
|
| 1041 |
(*status) = SERVER_W3XP_CLAN_MEMBER_PRIVATE_GAME;
|
| 1042 |
else
|
| 1043 |
(*status) = SERVER_W3XP_CLAN_MEMBER_GAME;
|
| 1044 |
return game_get_name(game);
|
| 1045 |
}
|
| 1046 |
if ((channel = conn_get_channel(conn)) != NULL)
|
| 1047 |
{
|
| 1048 |
(*status) = SERVER_W3XP_CLAN_MEMBER_CHANNEL;
|
| 1049 |
return channel_get_name(channel);
|
| 1050 |
}
|
| 1051 |
|
| 1052 |
(*status) = SERVER_W3XP_CLAN_MEMBER_ONLINE;
|
| 1053 |
} else
|
| 1054 |
(*status) = SERVER_W3XP_CLAN_MEMBER_OFFLINE;
|
| 1055 |
return NULL;
|
| 1056 |
}
|
| 1057 |
|
| 1058 |
extern int clanmember_set_online(t_connection * c)
|
| 1059 |
{
|
| 1060 |
t_clanmember *member;
|
| 1061 |
t_account *acc;
|
| 1062 |
|
| 1063 |
if (!c)
|
| 1064 |
{
|
| 1065 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection");
|
| 1066 |
return -1;
|
| 1067 |
}
|
| 1068 |
|
| 1069 |
if ((acc = conn_get_account(c)) && (member = account_get_clanmember(acc)))
|
| 1070 |
{
|
| 1071 |
clanmember_on_change_status(member);
|
| 1072 |
}
|
| 1073 |
|
| 1074 |
return 0;
|
| 1075 |
}
|
| 1076 |
|
| 1077 |
extern int clanmember_set_offline(t_connection * c)
|
| 1078 |
{
|
| 1079 |
t_clanmember *member;
|
| 1080 |
t_account *acc;
|
| 1081 |
|
| 1082 |
if (!c)
|
| 1083 |
{
|
| 1084 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection");
|
| 1085 |
return -1;
|
| 1086 |
}
|
| 1087 |
|
| 1088 |
if ((acc = conn_get_account(c)) && (member = account_get_clanmember_forced(acc)))
|
| 1089 |
{
|
| 1090 |
clanmember_on_change_status(member);
|
| 1091 |
}
|
| 1092 |
|
| 1093 |
return 0;
|
| 1094 |
}
|
| 1095 |
|
| 1096 |
extern int clan_get_created(t_clan * clan)
|
| 1097 |
{
|
| 1098 |
if (!(clan))
|
| 1099 |
{
|
| 1100 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1101 |
return -1;
|
| 1102 |
}
|
| 1103 |
|
| 1104 |
return clan->created;
|
| 1105 |
}
|
| 1106 |
|
| 1107 |
extern int clan_set_created(t_clan * clan, int created)
|
| 1108 |
{
|
| 1109 |
if (!(clan))
|
| 1110 |
{
|
| 1111 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1112 |
return -1;
|
| 1113 |
}
|
| 1114 |
|
| 1115 |
clan->created = created;
|
| 1116 |
|
| 1117 |
return 0;
|
| 1118 |
}
|
| 1119 |
|
| 1120 |
extern char clan_get_modified(t_clan * clan)
|
| 1121 |
{
|
| 1122 |
if (!(clan))
|
| 1123 |
{
|
| 1124 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1125 |
return -1;
|
| 1126 |
}
|
| 1127 |
|
| 1128 |
return clan->modified;
|
| 1129 |
}
|
| 1130 |
|
| 1131 |
extern int clan_set_modified(t_clan * clan, char modified)
|
| 1132 |
{
|
| 1133 |
if (!(clan))
|
| 1134 |
{
|
| 1135 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1136 |
return -1;
|
| 1137 |
}
|
| 1138 |
|
| 1139 |
clan->modified = modified;
|
| 1140 |
|
| 1141 |
return 0;
|
| 1142 |
}
|
| 1143 |
|
| 1144 |
extern char clan_get_channel_type(t_clan * clan)
|
| 1145 |
{
|
| 1146 |
if (!(clan))
|
| 1147 |
{
|
| 1148 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1149 |
return -1;
|
| 1150 |
}
|
| 1151 |
|
| 1152 |
return clan->channel_type;
|
| 1153 |
}
|
| 1154 |
|
| 1155 |
extern int clan_set_channel_type(t_clan * clan, char channel_type)
|
| 1156 |
{
|
| 1157 |
if (!(clan))
|
| 1158 |
{
|
| 1159 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1160 |
return -1;
|
| 1161 |
}
|
| 1162 |
|
| 1163 |
clan->channel_type = channel_type;
|
| 1164 |
|
| 1165 |
return 0;
|
| 1166 |
}
|
| 1167 |
|
| 1168 |
extern t_list *clan_get_members(t_clan * clan)
|
| 1169 |
{
|
| 1170 |
if (!(clan))
|
| 1171 |
{
|
| 1172 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1173 |
return NULL;
|
| 1174 |
}
|
| 1175 |
|
| 1176 |
return clan->members;
|
| 1177 |
}
|
| 1178 |
|
| 1179 |
extern char const *clan_get_name(t_clan * clan)
|
| 1180 |
{
|
| 1181 |
if (!(clan))
|
| 1182 |
{
|
| 1183 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1184 |
return NULL;
|
| 1185 |
}
|
| 1186 |
|
| 1187 |
return clan->clanname;
|
| 1188 |
}
|
| 1189 |
|
| 1190 |
extern int clan_get_clantag(t_clan * clan)
|
| 1191 |
{
|
| 1192 |
if (!(clan))
|
| 1193 |
{
|
| 1194 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1195 |
return 0;
|
| 1196 |
}
|
| 1197 |
|
| 1198 |
return clan->clantag;
|
| 1199 |
}
|
| 1200 |
|
| 1201 |
extern char const *clan_get_motd(t_clan * clan)
|
| 1202 |
{
|
| 1203 |
if (!(clan))
|
| 1204 |
{
|
| 1205 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1206 |
return NULL;
|
| 1207 |
}
|
| 1208 |
|
| 1209 |
return clan->clan_motd;
|
| 1210 |
}
|
| 1211 |
|
| 1212 |
extern int clan_set_motd(t_clan * clan, const char *motd)
|
| 1213 |
{
|
| 1214 |
if (!(clan))
|
| 1215 |
{
|
| 1216 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1217 |
return -1;
|
| 1218 |
}
|
| 1219 |
if (!(motd))
|
| 1220 |
{
|
| 1221 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL motd");
|
| 1222 |
return -1;
|
| 1223 |
} else
|
| 1224 |
{
|
| 1225 |
if (clan->clan_motd)
|
| 1226 |
xfree((void *) clan->clan_motd);
|
| 1227 |
clan->clan_motd = xstrdup(motd);
|
| 1228 |
}
|
| 1229 |
return 0;
|
| 1230 |
}
|
| 1231 |
|
| 1232 |
extern unsigned int clan_get_clanid(t_clan * clan)
|
| 1233 |
{
|
| 1234 |
if (!(clan))
|
| 1235 |
{
|
| 1236 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1237 |
return -1;
|
| 1238 |
}
|
| 1239 |
|
| 1240 |
return clan->clanid;
|
| 1241 |
}
|
| 1242 |
|
| 1243 |
extern int clan_set_creation_time(t_clan * clan, time_t c_time)
|
| 1244 |
{
|
| 1245 |
if (!(clan))
|
| 1246 |
{
|
| 1247 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1248 |
return -1;
|
| 1249 |
}
|
| 1250 |
|
| 1251 |
clan->creation_time = c_time;
|
| 1252 |
|
| 1253 |
return 0;
|
| 1254 |
}
|
| 1255 |
|
| 1256 |
extern time_t clan_get_creation_time(t_clan * clan)
|
| 1257 |
{
|
| 1258 |
if (!(clan))
|
| 1259 |
{
|
| 1260 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1261 |
return 0;
|
| 1262 |
}
|
| 1263 |
|
| 1264 |
return clan->creation_time;
|
| 1265 |
}
|
| 1266 |
|
| 1267 |
extern t_clanmember *clan_add_member(t_clan * clan, t_account * memberacc, char status)
|
| 1268 |
{
|
| 1269 |
t_clanmember *member;
|
| 1270 |
|
| 1271 |
if (!(clan))
|
| 1272 |
{
|
| 1273 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan");
|
| 1274 |
return NULL;
|
| 1275 |
}
|
| 1276 |
|
| 1277 |
if (!(clan->members))
|
| 1278 |
{
|
| 1279 |
eventlog(eventlog_level_error, __FUNCTION__, "found NULL clan->members");
|
| 1280 |
return NULL;
|
| 1281 |
}
|
| 1282 |
|
| 1283 |
member = xmalloc(sizeof(t_clanmember));
|
| 1284 |
member->memberacc = memberacc;
|
| 1285 |
member->status = status;
|
| 1286 |
member->join_time = now;
|
| 1287 |
member->clan = clan;
|
| 1288 |
#ifdef WITH_SQL
|
| 1289 |
member->modified = 1;
|
| 1290 |
#endif
|
| 1291 |
|
| 1292 |
list_append_data(clan->members, member);
|
| 1293 |
|
| 1294 |
account_set_clanmember(memberacc, member);
|
| 1295 |
|
| 1296 |
clan->modified = 1;
|
| 1297 |
|
| 1298 |
return member;
|
| 1299 |
}
|
| 1300 |
|
| 1301 |
extern int clan_remove_member(t_clan * clan, t_clanmember * member)
|
| 1302 |
{
|
| 1303 |
t_elem * elem;
|
| 1304 |
|
| 1305 |
if (!member)
|
| 1306 |
return -1;
|
| 1307 |
if (list_remove_data(clan->members, member, &elem) < 0)
|
| 1308 |
{
|
| 1309 |
eventlog(eventlog_level_error, __FUNCTION__, "could not remove member");
|
| 1310 |
return -1;
|
| 1311 |
}
|
| 1312 |
if (member->memberacc != NULL)
|
| 1313 |
{
|
| 1314 |
account_set_clanmember(member->memberacc, NULL);
|
| 1315 |
storage->remove_clanmember(account_get_uid(member->memberacc));
|
| 1316 |
}
|
| 1317 |
xfree((void *) member);
|
| 1318 |
clan->modified = 1;
|
| 1319 |
return 0;
|
| 1320 |
}
|
| 1321 |
|
| 1322 |
extern t_clan *clan_create(t_account * chieftain_acc, int clantag, const char *clanname, const char *motd)
|
| 1323 |
{
|
| 1324 |
t_clan *clan;
|
| 1325 |
t_clanmember *member;
|
| 1326 |
|
| 1327 |
clan = xmalloc(sizeof(t_clan));
|
| 1328 |
member = xmalloc(sizeof(t_clanmember));
|
| 1329 |
|
| 1330 |
if (!(clanname))
|
| 1331 |
{
|
| 1332 |
eventlog(eventlog_level_error, __FUNCTION__, "got NULL clanname");
|
| 1333 |
xfree((void *) clan);
|
| 1334 |
xfree((void *) member);
|
| 1335 |
return NULL;
|
| 1336 |
}
|
| 1337 |
|
| 1338 |
clan->clanname = xstrdup(clanname);
|
| 1339 |
|
| 1340 |
if (!(motd))
|
| 1341 |
clan->clan_motd = xstrdup("This is a newly created clan");
|
| 1342 |
else
|
| 1343 |
clan->clan_motd = xstrdup(motd);
|
| 1344 |
|
| 1345 |
clan->creation_time = now;
|
| 1346 |
clan->clantag = clantag;
|
| 1347 |
clan->clanid = ++max_clanid;
|
| 1348 |
clan->created = 0;
|
| 1349 |
clan->modified = 1;
|
| 1350 |
clan->channel_type = prefs_get_clan_channel_default_private();
|
| 1351 |
|
| 1352 |
clan->members = list_create();
|
| 1353 |
|
| 1354 |
member->memberacc = chieftain_acc;
|
| 1355 |
member->status = CLAN_CHIEFTAIN;
|
| 1356 |
member->join_time = clan->creation_time;
|
| 1357 |
member->clan = clan;
|
| 1358 |
#ifdef WITH_SQL
|
| 1359 |
member->modified = 1;
|
| 1360 |
#endif
|
| 1361 |
|
| 1362 |
list_append_data(clan->members, member);
|
| 1363 |
|
| 1364 |
account_set_clanmember(chieftain_acc, member);
|
| 1365 |
|
| 1366 |
return clan;
|
| 1367 |
}
|
| 1368 |
|
| 1369 |
extern int clan_destroy(t_clan * clan)
|
| 1370 |
{
|
| 1371 |
if (!clan)
|
| 1372 |
return 0;
|
| 1373 |
if (clan->clanname)
|
| 1374 |
xfree((void *) clan->clanname);
|
| 1375 |
if (clan->clan_motd)
|
| 1376 |
xfree((void *) clan->clan_motd);
|
| 1377 |
clan_remove_all_members(clan);
|
| 1378 |
xfree((void *) clan);
|
| 1379 |
return 0;
|
| 1380 |
}
|
| 1381 |
|
| 1382 |
extern int clan_get_member_count(t_clan * clan)
|
| 1383 |
{
|
| 1384 |
t_elem *curr;
|
| 1385 |
int count = 0;
|
| 1386 |
LIST_TRAVERSE(clan->members, curr)
|
| 1387 |
{
|
| 1388 |
if ((elem_get_data(curr)) != NULL)
|
| 1389 |
count++;
|
| 1390 |
}
|
| 1391 |
return count;
|
| 1392 |
}
|
| 1393 |
|
| 1394 |
extern int str_to_clantag(const char *str)
|
| 1395 |
{
|
| 1396 |
int clantag = 0;
|
| 1397 |
|
| 1398 |
if (!str)
|
| 1399 |
return 0;
|
| 1400 |
|
| 1401 |
if (str[0])
|
| 1402 |
{
|
| 1403 |
clantag = str[0] << 24;
|
| 1404 |
if (str[1])
|
| 1405 |
{
|
| 1406 |
clantag += str[1] << 16;
|
| 1407 |
if (str[2])
|
| 1408 |
{
|
| 1409 |
clantag += str[2] << 8;
|
| 1410 |
if (str[3])
|
| 1411 |
clantag += str[3];
|
| 1412 |
}
|
| 1413 |
}
|
| 1414 |
}
|
| 1415 |
return clantag;
|
| 1416 |
|
| 1417 |
}
|