I added the ability for mq2telnet to listen on multiple ports. This allows it to be loaded on multiple characters on the same pc, each on a different port. Login usernames are shared across ports. Tested on 6 accounts on same computer, 6 different ports.
None of the other required .cpp/.h files were changed for this so I did not post them (but I can if needed).
mq2telnet.ini format:
None of the other required .cpp/.h files were changed for this so I did not post them (but I can if needed).
mq2telnet.ini format:
Rich (BB code):
;**********************************************************************
; for use with the telnet server plugin -- mq2telnet
;**********************************************************************
[Users]
;username=password
[servername_charname]
; port = 0 off, else put the port number here
Port=0
; localonly boolean -- supposedly does a get peer name to compare address
; but you must use the hostname not 127.0.0.1 or localhost when connecting
LocalOnly=0
Welcome=Successful login. Welcome to my undergroud lair.
LoginPrompt=login:
PasswordPrompt=password:
[servername_otherchar]
; port = 0 off, else put a different port number here
Port=0
; localonly boolean -- supposedly does a get peer name to compare address
; but you must use the hostname not 127.0.0.1 or localhost when connecting
LocalOnly=0
Welcome=Successful login. Welcome to my undergroud lair.
LoginPrompt=login:
PasswordPrompt=password:
Rich (BB code):
// mq2telnet.cpp
// Updated 2/1/2012 by Sym - Added multiple ports option in same mq2telnet.ini
//#define DEBUG_TRY
#include "../MQ2Plugin.h"
#include "WinTelnet.h"
#include "TelnetServer.h"
PreSetup("MQ2Telnet");
CTelnetServer *server=0;
bool needsInit = true;
DWORD TelnetPort=0;
PLUGIN_API VOID SetGameState(DWORD GameState)
{
if (GameState==GAMESTATE_INGAME && needsInit)
{
CHAR SectionName[MAX_STRING] = {0};
CHAR szTemp[MAX_STRING] = {0};
needsInit = false;
sprintf(SectionName, "%s_%s", EQADDR_SERVERNAME, ((PCHARINFO)pCharData)->Name);
TelnetPort = GetPrivateProfileInt(SectionName,"Port",0,INIFileName);
if (TelnetPort)
{
// ANSI not currently implemented
//TelnetPort = GetPrivateProfileInt(SectionName,"ANSI",1,INIFileName);
LocalOnly = GetPrivateProfileInt(SectionName,"LocalOnly",1,INIFileName);
GetPrivateProfileString(SectionName,"LoginPrompt","login: ",TelnetLoginPrompt,MAX_STRING,INIFileName);
GetPrivateProfileString(SectionName,"PassPrompt","password: ",TelnetPasswordPrompt,MAX_STRING,INIFileName);
GetPrivateProfileString(SectionName,"Welcome","Successful login.",TelnetWelcome,MAX_STRING,INIFileName);
server=new CTelnetServer();
server->Listen(TelnetPort);
sprintf(szTemp, "MQ2Telnet is listening on port %i", TelnetPort);
WriteChatColor(szTemp, CONCOLOR_LIGHTBLUE);
} else {
DebugSpewAlways("SetupServer: Port 0 specified, disabling mq2telnet");
WriteChatColor("MQ2Telnet has no port defined. Set your port in mq2telnet.ini and reload the plugin.",CONCOLOR_RED);
}
}
}
PLUGIN_API VOID InitializePlugin(VOID)
{
DebugSpewAlways("Initializing mq2telnet");
}
PLUGIN_API VOID ShutdownPlugin(VOID)
{
DebugSpewAlways("Shutting down mq2telnet");
CTelnetServer *pServer=server;
server=0;
if (pServer)
{
DebugTry(delete pServer);
}
}
PLUGIN_API VOID OnPulse(VOID)
{
if (server)
server->ProcessIncoming();
}
PLUGIN_API DWORD OnWriteChatColor(PCHAR Line, DWORD Color, DWORD Filter)
{
CHAR Stripped[MAX_STRING];
//if (gFilterMacro == FILTERMACRO_NONE) return 0;
if (server)
{
// ANSI not currently implemented
//if (ANSI)
// MQToANSI(Line,Stripped);
//else
StripMQChat(Line,Stripped);
server->Broadcast(Stripped);
}
return 0;
}
PLUGIN_API DWORD OnIncomingChat(PCHAR Line, DWORD Color)
{
CHAR Stripped[MAX_STRING];
if (server)
{
// ANSI not currently implemented
//if (ANSI)
// MQToANSI(Line,Stripped);
//else
StripMQChat(Line,Stripped);
server->Broadcast(Stripped);
}
return 0;
}
Last edited: