Jump to content

[C++] Maintenance system


Guest Ezrekith

Recommended Posts

Guest Ezrekith

Hi folks!


[

Karbantartás érkezik = Incoming maintenance

59 perc 58 mp múltva! = 59 minutes 58 seconds left!

Várható időtartama = Maintenance duration

10 perc = 10 minutes

]

59ea5eb3bdd95_Nvtelen.png.c276a9c3c85c1c37b3db257efb1887c9.png
Lets start with the Python because its almost nothing!

root/game.py

#Search for:

def BINARY_Cube_Open(self, npcVNUM):
  
  
#Add above:

	if app.ENABLE_MAINTENANCE_SYSTEM:
		def BINARY_Maintenance(self, sec, dur):
			sec = int(sec)
			dur = int(dur)
			self.interface.StartMaintenance(sec,dur)

root/interfacemodule.py

#Search for:

import guild

#Add under:

if app.ENABLE_MAINTENANCE_SYSTEM:
	import uimaintenance

#Search for:

self.wndGuildBuilding = None

#Add under:
		if app.ENABLE_MAINTENANCE_SYSTEM:
			self.wndMaintenanceInfo = None

#Search for:

		if self.wndGameButton:
			self.wndGameButton.Destroy()

#Add under:

		if app.ENABLE_MAINTENANCE_SYSTEM:
			if self.wndMaintenanceInfo:
				self.wndMaintenanceInfo.Destroy()
	
#Search for:
	
		del self.wndItemSelect
	
#Add under:

		if app.ENABLE_MAINTENANCE_SYSTEM:
			del self.wndMaintenanceInfo
			
#Search for:

	def EmptyFunction(self):
		pass
		
#Add under:

	if app.ENABLE_MAINTENANCE_SYSTEM:
		def StartMaintenance(self, timeLimit, duration):
			if not self.wndMaintenanceInfo:
				self.wndMaintenanceInfo = uimaintenance.MaintenanceInfoBoard()
			if timeLimit > 0:
				self.wndMaintenanceInfo.SetTimeLimit(timeLimit, duration)
				self.wndMaintenanceInfo.Show()
			else:
				self.wndMaintenanceInfo.Hide()

root/localeinfo.py

#Search for:

return text + insertingText + backText


#Add under:

def SecondToDHMS(time):

	second = int(time % 60)
	minute = int((time / 60) % 60)
	hour = int(((time / 60) / 60) % 24)
	day = int(((time / 60) / 60) / 24)

	text = ""

	if day > 0:
		if day == 1:
			text += str(day) + " Day "
		else:
			text += str(day) + " Day "

	if hour > 0:
		text += str(hour) + " " + "Hour" + " "

	if minute > 0:
		text += str(minute) + " " + "Minute" + " "

	if second > 0 or (day == 0 and hour == 0 and minute == 0):
		text += str(second) + " " + "Sec" + " "

	return text[:-1]

Create a file which is called: uimaintenance.py

import ui
import wndMgr
import localeInfo
import uiScriptLocale
import app

class MaintenanceInfoBoard(ui.ThinBoard):

	BOARD_WIDTH = 420
	BOARD_HEIGHT = 40
	SPECIAL_TITLE_COLOR = grp.GenerateColor(1.0, 0.7843, 0.0, 1.0)
	
	def __init__(self):
		ui.ThinBoard.__init__(self)
		self.AddFlag("float")
		self.timeLimitEnd = 0
		self.duration = 0
	
		text1 = ui.TextLine()
		text1.SetParent(self)
		text1.SetText("Incoming Maintenance")
		text1.SetPosition(10,8)
		text1.SetPackedFontColor(self.SPECIAL_TITLE_COLOR)
		text1.Show()
		self.text1 = text1
	
		timeTextLine = ui.TextLine()
		timeTextLine.SetParent(self)
		timeTextLine.SetPosition(10,25)
		timeTextLine.Show()
		self.timeTextLine = timeTextLine
		
		text2 = ui.TextLine()
		text2.SetParent(self)
		text2.SetText("Maintenance Duration")
		text2.SetPosition(10,25+17)
		text2.SetPackedFontColor(self.SPECIAL_TITLE_COLOR)
		text2.Show()
		self.text2 = text2
		
		timeTextLine2 = ui.TextLine()
		timeTextLine2.SetParent(self)
		timeTextLine2.SetPosition(10,25+17*2)
		timeTextLine2.Show()
		self.timeTextLine2 = timeTextLine2

		self.SetPosition(wndMgr.GetScreenWidth() - 180, 165)
		self.SetSize(self.BOARD_WIDTH, self.BOARD_HEIGHT)	

	def __del__(self):
		ui.ThinBoard.__del__(self)

	def SetTimeLimit(self, timeLimit, duration=0):
		if timeLimit > 0:
			self.timeLimitEnd = timeLimit
			self.duration = duration
			self.__Refresh()
		else:
			self.timeLimitEnd = 0
			self.duration = 0
			self.Hide()

	def __Refresh(self):
		self.timeTextLine.SetText("%s |cffFFC700left!" % (localeInfo.SecondToDHMS(self.timeLimitEnd)))
		self.timeTextLine2.SetText("%s" % (localeInfo.SecondToDHMS(self.duration)))

	def Close(self):
		self.Hide()

________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Binary/packet.h

//Add this to the includes if you don't have:

#include "Locale_inc.h"

//Search for:

HEADER_CG_SCRIPT_SELECT_ITEM				= 114,

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
HEADER_GC_MAINTENANCE						= 155,
#endif


//Search for:

#pragma pack(pop)

//Add above:

#ifdef ENABLE_MAINTENANCE_SYSTEM
typedef struct SPacketGCGetMaintenance {
	BYTE	header;
	int		seconds;
	int		duration;
} TPacketGCMaintenance;
#endif

Binary/PythonApplicationModule.cpp

//Add this to the includes if you don't have:

#include "Locale_inc.h"

//Search for:

PyModule_AddIntConstant(poModule, "CAMERA_STOP",			CPythonApplication::CAMERA_STOP);

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
	PyModule_AddIntConstant(poModule, "ENABLE_MAINTENANCE_SYSTEM", 1);
#else
	PyModule_AddIntConstant(poModule, "ENABLE_MAINTENANCE_SYSTEM", 0);
#endif

Binary/PythonNetworkStream.cpp

//Add this to the includes if you don't have:

#include "Locale_inc.h"

//Search for:

Set(HEADER_GC_DRAGON_SOUL_REFINE,		CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCDragonSoulRefine), STATIC_SIZE_PACKET));

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
Set(HEADER_GC_MAINTENANCE, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCMaintenance), STATIC_SIZE_PACKET));
#endif

Binary/PythonNetworkStream.h

//Add this to the includes if you don't have:

#include "Locale_inc.h"

//Search for:

DWORD EXPORT_GetBettingGuildWarValue(const char* c_szValueName);

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
bool RecvMaintenance();
#endif

Binary/PythonNetworkStreamPhaseGame.cpp

//Add this to the includes if you don't have:

#include "Locale_inc.h"

//Search for:

			case HEADER_GC_DRAGON_SOUL_REFINE:
				ret = RecvDragonSoulRefine();
				break;

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
			case HEADER_GC_MAINTENANCE:
				ret = RecvMaintenance();
				break;
#endif

//Search for:

struct PERF_PacketInfo
{
	[...]
};

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM		
bool CPythonNetworkStream::RecvMaintenance()
{
	TPacketGCMaintenance packet;
	if (!Recv(sizeof(packet), &packet))
		return false;

	PyCallClassMemberFunc(m_apoPhaseWnd[PHASE_WINDOW_GAME], "BINARY_Maintenance",
		Py_BuildValue("(ii)", packet.seconds, packet.duration));

	return true;
}
#endif

Source/game/cmd.cpp

//Add this to the includes if you don't have:

#include "../common/service.h"

//Search for:

ACMD (do_clear_affect);

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
ACMD(do_maintenance);
#endif

//Search for:

{ "do_clear_affect", do_clear_affect, 	0, POS_DEAD,		GM_LOW_WIZARD},

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
{ "maintenance",				do_maintenance,				0,					POS_DEAD,		GM_IMPLEMENTOR},
#endif

Source/game/cmd_gm.cp

//Add this to the includes if you don't have:

#include "../common/service.h"

//Search for:

ACMD (do_ds_list)
{
	[...]
}

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
EVENTINFO(maintenance_event_data)
{
	int seconds;
	int duration;
	maintenance_event_data()
	: seconds( 0 ), duration( 0 )
	{
	}
};

EVENTFUNC(maintenance_event)
{
	maintenance_event_data* info = dynamic_cast<maintenance_event_data*>( event->info);

	if ( info == NULL )
	{
		sys_err( "maintenance_event> <Factor> Null pointer" );
		return 0;
	}

	int * pSec = & (info->seconds);
	
	int iDur = info->duration;

	const DESC_MANAGER::DESC_SET & c_set_desc = DESC_MANAGER::instance().GetClientSet();
	for (itertype(c_set_desc) it = c_set_desc.begin(); it != c_set_desc.end(); it++)
	{
		LPDESC d = *(it);
		if (d->IsPhase(PHASE_P2P))
		{		
			TPacketGCMaintenance p;
			p.header = HEADER_GG_MAINTENANCE;
			p.seconds = info->seconds;
			p.duration = iDur;
			d->Packet(&p, sizeof(p));
		}
		if(d->GetCharacter())
		{
			TPacketGCMaintenance p;
			p.header = HEADER_GC_MAINTENANCE;
			p.seconds = info->seconds;
			p.duration = iDur;
			d->Packet(&p, sizeof(p));
		}
	}
	if (pSec > 0)
		--*pSec;
	return passes_per_sec;
	
}

LPEVENT m_pkMantenanceEvent = NULL;

ACMD(do_maintenance)
{
	if (m_pkMantenanceEvent)
		event_cancel(&m_pkMantenanceEvent);
	
	if (!ch)
		return;
	
	if (ch->GetGMLevel() < GM_IMPLEMENTOR)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You have to be an Server Admin."));
		return;
	}

	char arg1[256];
	char arg2[256];
	two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2));

	if (!*arg1 || !*arg2)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Usage: maintenance <time> <durration min>(0 to off) (1m 30s)"));
		return;
	}

	int StartSec = parse_time_str(arg1);
	int DurSec = parse_time_str(arg2);

	if (StartSec < 0)
	{
		if (ch)
		{
			ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("=> 10s, 10m, 1m 30s"));
		}
		return;
	}

	maintenance_event_data* info = AllocEventInfo<maintenance_event_data>();
	info->seconds = StartSec;
	info->duration = DurSec;

	m_pkMantenanceEvent = event_create(maintenance_event, info, 1);
	
}
#endif

 

Source/game/input.h

//Add this to the includes if you don't have:

#include "../common/service.h"

//Search for:

void		IamAwake(LPDESC d, const char * c_pData);

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
void		Maintenance(const char * c_pData);
#endif

 

Source/game/input_p2p,cpp

//Add this to the includes if you don't have:

#include "../common/service.h"

//Search for:

void CInputP2P::IamAwake(LPDESC d, const char * c_pData)
{
	[...]
}

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
struct FuncMaintenance
{
	int seconds;
	int duration;
	
	FuncMaintenance(int x, int y) : seconds(x), duration(y)
	{
	}   

	void operator () (LPDESC d)
	{
		if(!d->GetCharacter())
			return;
		
		TPacketGCMaintenance p;
		p.header = HEADER_GC_MAINTENANCE;
		p.seconds = seconds;
		p.duration = duration;
		d->Packet(&p, sizeof(p));
	}
};

void CInputP2P::Maintenance(const char * c_pData)
{
	TPacketGCMaintenance* p = (TPacketGCMaintenance*) c_pData;
	const DESC_MANAGER::DESC_SET & c_ref_set = DESC_MANAGER::instance().GetClientSet();
	std::for_each(c_ref_set.begin(), c_ref_set.end(), FuncMaintenance(p->seconds, p->duration));
}
#endif

//Search for:

		case HEADER_GG_CHECK_AWAKENESS:
			IamAwake(d, c_pData);
			break;

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
		case HEADER_GG_MAINTENANCE:
			Maintenance(c_pData);
			break;
#endif

 

Source/game/packet.h

//Add this to the includes if you don't have:

#include "../common/service.h"

//Search for:

HEADER_CG_SCRIPT_SELECT_ITEM	= 114,

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
HEADER_GC_MAINTENANCE						= 155,
#endif


//Search for:

HEADER_GC_QUEST_CONFIRM			= 46,

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
HEADER_GG_MAINTENANCE						= 47,
#endif

//Search for:

#pragma pack()

//Add above:
#ifdef ENABLE_MAINTENANCE_SYSTEM
typedef struct SPacketGCGetMaintenance {
	BYTE	header;
	int		seconds;
	int		duration;
} TPacketGCMaintenance;
#endif

 

Source/game/packet_info.cpp

//Add this to the includes if you don't have:

#include "../common/service.h"

//Search for:

Set(HEADER_GG_CHECK_AWAKENESS,		sizeof(TPacketGGCheckAwakeness),	"CheckAwakeness",		false);

//Add under:

#ifdef ENABLE_MAINTENANCE_SYSTEM
Set(HEADER_GG_MAINTENANCE, sizeof(TPacketGCMaintenance), "Maintenance", false);
#endif

 

Locale_inc.h & service.h

#define ENABLE_MAINTENANCE_SYSTEM

Usage:

Login with a GM IMPLEMENTOR character and type:

/maintenance 1h 10m

So this will set the maintenance time to 1 hour and the duration to 10 minutes...

 

Edited by Ezrekith
Link to post
Share on other sites
  • 1 month later...
Guest Ezrekith

Your 155 packet is used, search something else for example 156,157 and replace the 155 packet in client and game src too.

 

But it's clearly written down: '155' Already used... :anon: 

Edited by Ezrekith
Link to post
Share on other sites
  • 2 years later...
  • 4 weeks later...
  • 5 months later...
  • 3 months later...
  • 1 month later...
  • 2 months later...
  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...