Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions blakserv/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,33 @@ void GameSendSystemEnter(session_node *s)
SendTopLevelBlakodMessage(GetSystemObjectID(),SYSTEM_ENTER_GAME_MSG,1,&p);
}

/* The client sends the player's object id as decimal text. Returns the id
* if it names an existing object, otherwise INVALID_OBJECT, so the text
* can't add anything else to the admin command it is put into.
*/
static int GameDMParseObjectID(const char *str)
{
char *end;
long object_id;

if (str == NULL)
return INVALID_OBJECT;

object_id = strtol(str, &end, 10);
if (end == str || *end != '\0' || object_id <= 0 || object_id > INT_MAX)
return INVALID_OBJECT;

if (GetObjectByIDQuietly((int) object_id) == NULL)
return INVALID_OBJECT;

return (int) object_id;
}

void GameDMCommand(session_node *s, int type, char *str)
{
char buf[LEN_MAX_CLIENT_MSG + 200];
int acctype;
int object_id;

acctype = ACCOUNT_NORMAL;
if (!s || !s->account)
Expand Down Expand Up @@ -750,7 +773,10 @@ void GameDMCommand(session_node *s, int type, char *str)
break;
if (ConfigInt(RIGHTS_GOPLAYER) == ACCOUNT_ADMIN && acctype == ACCOUNT_DM)
break;
sprintf(buf, "send object %i admingotoobject what object %s", s->game->object_id, str);
object_id = GameDMParseObjectID(str);
if (object_id == INVALID_OBJECT)
break;
sprintf(buf, "send object %i admingotoobject what object %i", s->game->object_id, object_id);
SendSessionAdminText(s->session_id, "~B> %s\n", buf); /* echo it to 'em */
TryAdminCommand(s->session_id, buf);
break;
Expand All @@ -760,7 +786,10 @@ void GameDMCommand(session_node *s, int type, char *str)
break;
if (ConfigInt(RIGHTS_GETPLAYER) == ACCOUNT_ADMIN && acctype == ACCOUNT_DM)
break;
sprintf(buf, "send object %s admingotoobject what object %i", str, s->game->object_id);
object_id = GameDMParseObjectID(str);
if (object_id == INVALID_OBJECT)
break;
sprintf(buf, "send object %i admingotoobject what object %i", object_id, s->game->object_id);
SendSessionAdminText(s->session_id, "~B> %s\n", buf); /* echo it to 'em */
TryAdminCommand(s->session_id, buf);
break;
Expand Down
62 changes: 43 additions & 19 deletions clientd3d/msgfiltr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static HWND hWhoDialog = NULL; /* Non-null if Who dialog is up */
extern player_info player;

#define WHOM_UPDATE (WM_APP+5)
#define WHOM_RESET (WM_APP+6)

Bool AddUserToIgnoreList(ID name)
{
Expand Down Expand Up @@ -70,42 +71,61 @@ void UpdateWho(object_node* pUser, BOOL bAdded)
SendMessage(hWhoDialog, WHOM_UPDATE, (WPARAM)bAdded, (LPARAM)pUser);
}

/*
* ResetWho: The list of current users is replaced; the who dialog must
* show the new list before the old one is freed.
*/
void ResetWho(list_type users)
{
if (hWhoDialog)
SendMessage(hWhoDialog, WHOM_RESET, 0, (LPARAM)users);
}

/*
* WhoSetUsers: Fill the who dialog's list box with the given users and
* highlight the ones we're not ignoring.
*/
static void WhoSetUsers(HWND hDlg, IDList users)
{
HWND hList = GetDlgItem(hDlg, IDC_USERLIST);
int num, i;

ItemListSetContents(hList, users, False);

num = ListBox_GetCount(hList);
for (i = 0; i < num; i++)
{
object_node *obj = (object_node *) ListBox_GetItemData(hList, i);
if (obj == NULL)
{
debug(("WhoDialogProc got NULL user entry\n"));
continue;
}
if (!IsUserInIgnoreList(obj->name_res))
ListBox_SetSel(hList, TRUE, i);
}

SetDlgItemInt(hDlg, IDC_NUMPLAYERS, num, FALSE);
}

/*****************************************************************************/
BOOL CALLBACK WhoDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
HWND hList;
IDList users;
int num, i;
Bool selected, ignored;

switch (message)
{
case WM_INITDIALOG:
CenterWindow(hDlg, GetParent(hDlg));
users = (IDList) lParam;
hList = GetDlgItem(hDlg, IDC_USERLIST);

// Don't draw objects; too slow to load user bitmaps
SetWindowLong(hList, GWL_USERDATA, OD_DRAWICON | OD_ONLYSEL | OD_COLORTEXT | OD_MAKEICONINDEX(0));

/* Set contents of user list */
ItemListSetContents(hList, users, False);

// Highlight people we're not ignoring
num = ListBox_GetCount(hList);
for (i = 0; i < num; i++)
{
object_node *obj = (object_node *) ListBox_GetItemData(hList, i);
if (obj == NULL)
{
debug(("WhoDialogProc got NULL user entry\n"));
continue;
}
if (!IsUserInIgnoreList(obj->name_res))
ListBox_SetSel(hList, TRUE, i);
}

SetDlgItemInt(hDlg, IDC_NUMPLAYERS, num, FALSE);
WhoSetUsers(hDlg, (IDList) lParam);

CheckDlgButton(hDlg, IDC_BROADCAST, config.no_broadcast);
CheckDlgButton(hDlg, IDC_IGNOREALL, config.ignore_all);
Expand All @@ -116,6 +136,10 @@ BOOL CALLBACK WhoDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
hWhoDialog = hDlg;
return TRUE;

case WHOM_RESET:
WhoSetUsers(hDlg, (IDList) lParam);
return TRUE;

case WHOM_UPDATE:
{
BOOL bAdded = (BOOL)wParam;
Expand Down
1 change: 1 addition & 0 deletions clientd3d/msgfiltr.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define _MSGFILTR_H

void UpdateWho(object_node* pUser, BOOL bAdded);
void ResetWho(list_type users);
BOOL CALLBACK WhoDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
void AbortWhoDialog(void);

Expand Down
4 changes: 3 additions & 1 deletion clientd3d/say.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ list_type current_users = NULL;
*/
void SetCurrentUsers(list_type users)
{
/* Destroy old list, and if dialog is up, reset user list box */
/* If dialog is up, reset user list box, then destroy old list */
ResetWho(users);
ObjectListDestroy(current_users);
current_users = users;
}
Expand Down Expand Up @@ -72,6 +73,7 @@ void RemoveCurrentUser(ID user_id)
*/
void FreeCurrentUsers(void)
{
ResetWho(NULL);
ObjectListDestroy(current_users);
current_users = NULL;
}
Expand Down
93 changes: 71 additions & 22 deletions clientd3d/srvrstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,57 @@

#include "client.h"

/************************************************************************/
/*
* FormatBounded: sprintf into dest, but never past end (one past the last
* byte of the buffer). Returns the number of characters written.
*/
static DWORD FormatBounded(char *dest, const char *end, const char *format, ...)
{
va_list args;
size_t room;
int written;

if (dest >= end)
return 0;

room = end - dest;
va_start(args, format);
written = vsnprintf(dest, room, format, args);
va_end(args);

if (written < 0)
{
*dest = '\0';
return 0;
}

if ((size_t) written >= room)
return (DWORD) (room - 1);

return (DWORD) written;
}
/************************************************************************/
/*
* AppendBounded: Copy up to len characters of src to *dest and null terminate,
* but never past end (one past the last byte of the buffer). Moves *dest
* past the copied characters.
*/
static void AppendBounded(char **dest, const char *end, const char *src, size_t len)
{
size_t room;

if (*dest >= end)
return;

room = end - *dest - 1;
if (len > room)
len = room;

strncpy(*dest, src, len);
*dest += len;
**dest = '\0';
}
/************************************************************************/
/*
* CheckServerMessage: Assemble a set of printf-style strings into a resultant
Expand All @@ -35,7 +86,7 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)
char* message;
char message2[MAXMESSAGE];
char* msg2 = message2; /* Pointer to message2 */
char *rsc, type_char, *orig_message;
char *rsc, type_char, *orig_message, *message_end;
DWORD field, num_chars;
WORD string_len;
Bool done = False;
Expand Down Expand Up @@ -87,6 +138,7 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)

/* Prepare to format into the caller's message buffer. */
orig_message = message;
message_end = orig_message + MAXMESSAGE;

/* Keep looping through string until there's nothing left to replace */
while (!done)
Expand Down Expand Up @@ -149,7 +201,7 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)
{
case '%': /* %% ==> % */
// Add what we have so far to the message (including one of the %s).
num_chars = sprintf(message, tempfmt);
num_chars = FormatBounded(message, message_end, tempfmt);
message += num_chars;
break;
case 'r':
Expand Down Expand Up @@ -180,14 +232,15 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)
// but we have to remove the 'r' and add %s as %r isn't a valid
// sprintf formatter, while %s is.
// Copy the part before the %r modifier into message.
num_chars = sprintf(message, tempfmt);
num_chars = FormatBounded(message, message_end, tempfmt);

if (!skip)
{
// Increment message, but remove the 'r' character.
message += (num_chars - 1);
if (num_chars > 0)
message += (num_chars - 1);
// Copy the msg2 string into message.
num_chars = sprintf(message, "%s", msg2);
num_chars = FormatBounded(message, message_end, "%s", msg2);
}
else
{
Expand Down Expand Up @@ -229,17 +282,17 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)
if ((rsc = LookupRsc(field)) == NULL)
return False;

num_chars = sprintf(message, tempfmt, rsc);
num_chars = FormatBounded(message, message_end, tempfmt, rsc);
}
else
{
num_chars = sprintf(message, tempfmt, field);
num_chars = FormatBounded(message, message_end, tempfmt, field);
}
}
else
{
skip = False;
num_chars = sprintf(message, tempfmt);
num_chars = FormatBounded(message, message_end, tempfmt);
}
message += num_chars; /* Overwrite null char next time */

Expand Down Expand Up @@ -277,18 +330,17 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)
num_qparams++;
}

/* Copy this section of format string */
strncpy(message, tempfmt, (next_ptr - fmt));
/* Copy this section of format string; without the %q if skipped.
* Also adds a null terminator, so we can check length of string
* if there is an %r formatter next.
*/
if (!skip)
message += (next_ptr - fmt);
AppendBounded(&message, message_end, tempfmt, next_ptr - fmt);
else
{
skip = False;
message += (next_ptr - fmt - 2);
AppendBounded(&message, message_end, tempfmt, next_ptr - fmt - 2);
}
// Add a null terminator here so we can check length of string
// if there is an %r formatter next.
*message = '\0';

/* Skip string */
param_ptr += string_len;
Expand All @@ -312,7 +364,7 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)
}

/* Copy over last part of string */
strcpy(message, fmt);
AppendBounded(&message, message_end, fmt, strlen(fmt));

/* Prepare for next pass */
message = orig_message;
Expand Down Expand Up @@ -358,18 +410,15 @@ Bool CheckServerMessage(char** msg, char **params, long *len, ID fmt_id)
tempfmt[(next_ptr - fmt) - 2] = '\0';

/* Add tempfmt and then literal string to end of message */
strcpy(message, tempfmt);
message += strlen(tempfmt);

strncpy(message, param_ptr, string_len);
message += string_len;
AppendBounded(&message, message_end, tempfmt, strlen(tempfmt));
AppendBounded(&message, message_end, param_ptr, string_len);

fmt = next_ptr;
next_ptr = strchr(fmt, '%');
}

/* Copy over last part of string */
strcpy(message, fmt);
AppendBounded(&message, message_end, fmt, strlen(fmt));

return True;
}
Expand Down
6 changes: 6 additions & 0 deletions kod/object/active/holder/nomoveon/battler.kod
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ messages:
ptVigor = $;
}

if ptMinionControlCheck <> $
{
DeleteTimer(ptMinionControlCheck);
ptMinionControlCheck = $;
}

propagate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ messages:
ptAbsence = $;
}

if ptChat <> $
{
DeleteTimer(ptChat);
ptChat = $;
}

// If the follower had any minions, remove them.
Send(self,@RemoveAllMinions);

Expand Down
Loading
Loading