mirror of
https://github.com/Meridian59/Meridian59
synced 2026-08-17 18:23:09 -04:00
199 lines
5.3 KiB
C
199 lines
5.3 KiB
C
// Meridian 59, Copyright 1994-2012 Andrew Kirmse and Chris Kirmse.
|
|
// All rights reserved.
|
|
//
|
|
// This software is distributed under a license that is described in
|
|
// the LICENSE file that accompanies it.
|
|
//
|
|
// Meridian is a registered trademark.
|
|
/*
|
|
* admin.c: DLL that allows user to enter admin commands while in game mode.
|
|
*/
|
|
|
|
#include "client.h"
|
|
#include "admin.h"
|
|
|
|
HINSTANCE hInst; // Handle of this DLL
|
|
extern bool hidden; // true when dialog exists but is hidden
|
|
|
|
ClientInfo *c; // Holds data passed from main client
|
|
|
|
bool exiting;
|
|
|
|
/* local function prototypes */
|
|
static bool HandleAdmin(char *ptr, long len);
|
|
|
|
// Server message handler table
|
|
static handler_struct handler_table[] = {
|
|
{ BP_ADMIN, HandleAdmin },
|
|
{ 0, NULL},
|
|
};
|
|
|
|
// Client message table
|
|
client_message admin_msg_table[] = {
|
|
{ BP_REQ_ADMIN, { PARAM_STRING, PARAM_END }, },
|
|
{ 0, { PARAM_END }, },
|
|
};
|
|
|
|
// Key translation table
|
|
#define A_ADMIN (A_MODULE + 1)
|
|
#define A_LOOKINVENTORY (A_MODULE + 202) // Examine item in inventory (from merintr.dll)
|
|
|
|
static keymap admin_key_table[] = {
|
|
{ '4', KEY_SHIFT, A_ADMIN },
|
|
{ 0, 0, 0}, // Must end table this way
|
|
};
|
|
|
|
/****************************************************************************/
|
|
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD reason, LPVOID reserved)
|
|
{
|
|
switch (reason)
|
|
{
|
|
case DLL_PROCESS_ATTACH:
|
|
hInst = hModule;
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
/****************************************************************************/
|
|
void WINAPI GetModuleInfo(ModuleInfo *info, ClientInfo *client_info)
|
|
{
|
|
info->event_mask = EVENT_SERVERMSG | EVENT_USERACTION | EVENT_FONTCHANGED | EVENT_RESETDATA;
|
|
info->priority = PRIORITY_NORMAL;
|
|
info->module_id = MODULE_ID;
|
|
c = client_info; // Save client info for our use later
|
|
exiting = false;
|
|
|
|
KeyAddTable(GAME_PLAY, admin_key_table);
|
|
}
|
|
/****************************************************************************/
|
|
void WINAPI ModuleExit(void)
|
|
{
|
|
exiting = true;
|
|
|
|
KeyRemoveTable(GAME_PLAY, admin_key_table);
|
|
|
|
if (hAdminDlg != NULL)
|
|
DestroyWindow(hAdminDlg);
|
|
else PostMessage(c->hMain, BK_MODULEUNLOAD, 0, MODULE_ID);
|
|
}
|
|
|
|
/* event handlers */
|
|
/****************************************************************************/
|
|
/*
|
|
* EVENT_SERVERMSG
|
|
*/
|
|
/****************************************************************************/
|
|
bool WINAPI EventServerMessage(char *message, long len)
|
|
{
|
|
bool retval;
|
|
|
|
retval = LookupMessage(message, len, handler_table);
|
|
|
|
// If we handle message, don't pass it on to anyone else
|
|
if (retval == true)
|
|
return false;
|
|
|
|
return true; // Allow other modules to get other messages
|
|
}
|
|
/********************************************************************/
|
|
bool HandleAdmin(char *ptr, long len)
|
|
{
|
|
char message[COMBUFSIZE];
|
|
WORD length;
|
|
|
|
memcpy(&length, ptr, SIZE_STRING_LEN);
|
|
ptr += SIZE_STRING_LEN;
|
|
|
|
memcpy(message, ptr, length);
|
|
message[length] = 0;
|
|
|
|
if (hAdminDlg != NULL)
|
|
SendMessage(hAdminDlg, BK_GOTTEXT, 0, (LPARAM) message);
|
|
return true;
|
|
}
|
|
/****************************************************************************/
|
|
/*
|
|
* EVENT_USERACTION
|
|
*/
|
|
/****************************************************************************/
|
|
bool WINAPI EventUserAction(int action, void *action_data)
|
|
{
|
|
int x, y;
|
|
list_type objects;
|
|
char buf[MAX_ADMIN];
|
|
object_node *obj;
|
|
ID id;
|
|
|
|
switch (action)
|
|
{
|
|
case A_ADMIN:
|
|
if (hAdminDlg == NULL)
|
|
CreateDialog(hInst, MAKEINTRESOURCE(IDD_ADMIN), c->hMain, AdminDialogProc);
|
|
else
|
|
{
|
|
ShowWindow(hAdminDlg, SW_SHOWNORMAL);
|
|
SetFocus(hAdminDlg);
|
|
}
|
|
hidden = false;
|
|
|
|
break;
|
|
|
|
case A_LOOKMOUSE:
|
|
/* We're looking for a user clicking on main window */
|
|
if (hAdminDlg == NULL || hidden || !MouseToRoom(&x, &y))
|
|
return true;
|
|
|
|
objects = GetObjects3D(x, y, 0, 0, 0);
|
|
if (objects == NULL)
|
|
return true;
|
|
|
|
obj = (object_node *) (objects->data);
|
|
|
|
/* Get details of object */
|
|
sprintf(buf, "show object %d", GetObjId(obj->id));
|
|
SendMessage(hAdminDlg, BK_SENDCMD, 0, (LPARAM) buf);
|
|
break;
|
|
|
|
case A_LOOKINVENTORY:
|
|
// Examining inventory object
|
|
id = reinterpret_cast<std::intptr_t>(action_data);
|
|
if (hAdminDlg == NULL || hidden || id == INVALID_ID)
|
|
return true;
|
|
|
|
/* Get details of object */
|
|
sprintf(buf, "show object %d", GetObjId(id));
|
|
SendMessage(hAdminDlg, BK_SENDCMD, 0, (LPARAM) buf);
|
|
break;
|
|
|
|
default:
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
/****************************************************************************/
|
|
/*
|
|
* EVENT_FONTCHANGED
|
|
*/
|
|
/****************************************************************************/
|
|
bool WINAPI EventFontChanged(WORD font_id, LOGFONT *font)
|
|
{
|
|
if (hAdminDlg != NULL)
|
|
SendMessage(hAdminDlg, BK_SETDLGFONTS, 0, 0);
|
|
return true;
|
|
}
|
|
/****************************************************************************/
|
|
/*
|
|
* EVENT_RESETDATA
|
|
*/
|
|
/****************************************************************************/
|
|
bool WINAPI EventResetData(void)
|
|
{
|
|
// Clear all object info from dialog, since these might have changed
|
|
if (hAdminDlg != NULL)
|
|
SendMessage(hAdminDlg, BK_RESETDATA, 0, 0);
|
|
return true;
|
|
}
|
|
|