Atrinik Server  4.0
tell.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 #include <toolkit/string.h>
34 #include <player.h>
35 #include <object.h>
36 
38 void command_tell(object *op, const char *command, char *params)
39 {
40  char name[MAX_BUF], *msg, buf[HUGE_BUF];
41  size_t pos;
42  player *pl;
43 
44  pos = 0;
45 
46  if (!string_get_word(params, &pos, ' ', name, sizeof(name), '"')) {
47  draw_info(COLOR_WHITE, op, "Tell whom what?");
48  return;
49  }
50 
51  msg = player_sanitize_input(params + pos);
52 
53  if (!msg) {
54  draw_info_format(COLOR_WHITE, op, "Tell %s what?", name);
55  return;
56  }
57 
58  pl = find_player(name);
59 
60  if (!pl) {
61  draw_info(COLOR_WHITE, op, "No such player.");
62  return;
63  }
64 
65  /* Send to yourself? Intelligent... */
66  if (pl == CONTR(op)) {
67  draw_info(COLOR_WHITE, op, "You tell yourself the news. Very smart.");
68  return;
69  }
70 
71  strncpy(pl->player_reply, op->name, sizeof(pl->player_reply) - 1);
72  pl->player_reply[sizeof(pl->player_reply) - 1] = '\0';
73 
74  LOG(CHAT, "[TELL] [%s] [%s] %s", op->name, name, msg);
75 
76  snprintf(buf, sizeof(buf), "[a=#charname]%s[/a] tells you: %s", op->name, msg);
77  draw_info_type(CHAT_TYPE_PRIVATE, NULL, COLOR_NAVY, pl->ob, buf);
78 
79  snprintf(buf, sizeof(buf), "You tell [a=#charname]%s[/a]: %s", pl->ob->name, msg);
80  draw_info_type(CHAT_TYPE_PRIVATE, NULL, COLOR_NAVY, op, buf);
81 
82  /* Auto-reply message available */
83  if (CONTR(pl->ob)->afk_auto_reply[0] != '\0') {
84  snprintf(buf, sizeof(buf), "[a=#charname]%s[/a] auto-replies: %s", pl->ob->name, CONTR(pl->ob)->afk_auto_reply);
85  draw_info_type(CHAT_TYPE_PRIVATE, NULL, COLOR_NAVY, op, buf);
86  } else if (CONTR(pl->ob)->afk) {
87  /* Player is AFK */
88  snprintf(buf, sizeof(buf), "[a=#charname]%s[/a] is currently [AFK].", pl->ob->name);
89  draw_info_type(CHAT_TYPE_PRIVATE, NULL, COLOR_NAVY, op, buf);
90  }
91 }
player * find_player(const char *plname)
Definition: player.c:96
object * ob
Definition: player.h:185
char player_reply[64]
Definition: player.h:566
char * player_sanitize_input(char *str)
Definition: player.c:1311
const char * name
Definition: object.h:168
void command_tell(object *op, const char *command, char *params)
Definition: tell.c:38