PDA

View Full Version : |Source| Gift for new muemu



Goten
28/04/2020, 07:09 PM
Olá, aqui está a Source para a entrega de presentes de boas-vindas.

Favor ler bem o conteúdo, pois existem linhas que incluem apenas funções existentes, basicamente o código está sendo deixado para as crianças do jardim de infância.

GameServer

GiftForNew.h

#pragma once

#define MAX_CLASS 7

struct GIFT_INFO
{
int Class;
int SetID;
int Level;
int Luck;
int Option;
int Excellent;
int Time;
};

class CGift
{
public:
CGift();
virtual ~CGift();
void Init();
void Load(char* path);
void SetInfo(GIFT_INFO info);
void GiftItem(LPOBJ lpObj);
public:
GIFT_INFO m_GiftInfo[MAX_CLASS];
};

extern CGift gGiftNew;

GiftForNew.cpp

#include "stdafx.h"
#include "GameServer.h"
#include "GameMain.h"
#include "Util.h"
#include "User.h"
#include "GiftForNew.h"
#include "CashShop.h"
#include "MemScript.h"
#include "Notice.h"
#include "DSProtocol.h"
#include "ItemManager.h"
#include "ServerInfo.h"

CGift gGiftNew;

CGift::CGift() // OK
{
this->Init();
}

CGift::~CGift() // OK
{

}

void CGift::Init() // OK
{
memset(this->m_GiftInfo,0,sizeof(this->m_GiftInfo));
}

void CGift::Load(char* path) // OK
{
CMemScript* lpMemScript = new CMemScript;

if(lpMemScript == 0)
{
ErrorMessageBox(MEM_SCRIPT_ALLOC_ERROR,path);
return;
}

if(lpMemScript->SetBuffer(path) == 0)
{
ErrorMessageBox(lpMemScript->GetLastError());
delete lpMemScript;
return;
}

this->Init();

try
{
while(true)
{
if(lpMemScript->GetToken() == TOKEN_END)
{
break;
}

if(strcmp("end",lpMemScript->GetString()) == 0)
{
break;
}

GIFT_INFO info;

info.Class = lpMemScript->GetNumber();

info.SetID = lpMemScript->GetAsNumber();

info.Level = lpMemScript->GetAsNumber();

info.Luck = lpMemScript->GetAsNumber();

info.Option = lpMemScript->GetAsNumber();

info.Excellent = lpMemScript->GetAsNumber();

info.Time = lpMemScript->GetAsNumber();

this->SetInfo(info);
}
}
catch(...)
{
ErrorMessageBox(lpMemScript->GetLastError());
}

delete lpMemScript;
}

void CGift::SetInfo(GIFT_INFO info) // OK
{
if(CHECK_RANGE(info.Class,MAX_CLASS) == 0)
{
return;
}

this->m_GiftInfo[info.Class] = info;
}

void CGift::GiftItem(LPOBJ lpObj)
{
if(gServerInfo.m_TheGift == 0)
{
return;
}

if(lpObj->TheGift >= 1)
{
return;
}

lpObj->TheGift += 1;
GDSaveTheGiftData(lpObj->Index);
int Days = this->m_GiftInfo[lpObj->Class].Time;
time_t t = time(NULL);
localtime(&t);
DWORD iTime = (DWORD)t + Days * 86400;
GDCreateItemSend(lpObj->Index,0xEB,0,0,GET_ITEM(7,this->m_GiftInfo[lpObj->Class].SetID),this->m_GiftInfo[lpObj->Class].Level,0,0,this->m_GiftInfo[lpObj->Class].Luck,this->m_GiftInfo[lpObj->Class].Option,-1,this->m_GiftInfo[lpObj->Class].Excellent,0,0,0,0,0xFF,iTime);
GDCreateItemSend(lpObj->Index,0xEB,0,0,GET_ITEM(8,this->m_GiftInfo[lpObj->Class].SetID),this->m_GiftInfo[lpObj->Class].Level,0,0,this->m_GiftInfo[lpObj->Class].Luck,this->m_GiftInfo[lpObj->Class].Option,-1,this->m_GiftInfo[lpObj->Class].Excellent,0,0,0,0,0xFF,iTime);
GDCreateItemSend(lpObj->Index,0xEB,0,0,GET_ITEM(9,this->m_GiftInfo[lpObj->Class].SetID),this->m_GiftInfo[lpObj->Class].Level,0,0,this->m_GiftInfo[lpObj->Class].Luck,this->m_GiftInfo[lpObj->Class].Option,-1,this->m_GiftInfo[lpObj->Class].Excellent,0,0,0,0,0xFF,iTime);
GDCreateItemSend(lpObj->Index,0xEB,0,0,GET_ITEM(10,this->m_GiftInfo[lpObj->Class].SetID),this->m_GiftInfo[lpObj->Class].Level,0,0,this->m_GiftInfo[lpObj->Class].Luck,this->m_GiftInfo[lpObj->Class].Option,-1,this->m_GiftInfo[lpObj->Class].Excellent,0,0,0,0,0xFF,iTime);
GDCreateItemSend(lpObj->Index,0xEB,0,0,GET_ITEM(11,this->m_GiftInfo[lpObj->Class].SetID),this->m_GiftInfo[lpObj->Class].Level,0,0,this->m_GiftInfo[lpObj->Class].Luck,this->m_GiftInfo[lpObj->Class].Option,-1,this->m_GiftInfo[lpObj->Class].Excellent,0,0,0,0,0xFF,iTime);
}



ServerInfo.cpp

gGiftNew.Load(gPath.GetFullPath("Custom\\GiftForNew.txt"));

User.h

struct OBJECTSTRUCT
{
BYTE TheGift; // only add in is struct
};


User.cpp

void gObjCharZeroSet(int aIndex) // OK
{
lpObj->TheGift = 0; // only add in is void
}

DsProtocol.cpp


void DGCharacterInfoRecv(SDHP_CHARACTER_INFO_RECV* lpMsg) // OK
{
gGiftNew.GiftItem(lpObj); // only add in is void
}

void GDSaveTheGiftData(int aIndex)
{
LPOBJ lpUser = &gObj[aIndex];
THEGIFT_GD_SAVE_DATA pRequest;
pRequest.header.set(0xD9, 0x07, sizeof(pRequest));
memcpy(pRequest.Name, lpUser->Name, 11);
pRequest.index = aIndex;
pRequest.TheGift = lpUser->TheGift;
gDataServerConnection.DataSend((BYTE*)&pRequest,pRequest.header.size);
}

DsProtocol.h

struct SDHP_CHARACTER_INFO_RECV
{
BYTE TheGift; // only add in is struct
};

struct THEGIFT_GD_SAVE_DATA
{
PSBMSG_HEAD header;
WORD index;
char Name[11];
BYTE TheGift;
};
//
void GDSaveTheGiftData(int aIndex);

ObjectManager.cpp

bool CObjectManager::CharacterInfoSet(BYTE* aRecv,int aIndex) // OK
{
lpObj->TheGift = lpMsg->TheGift; // only add in is bool
}


DataServer

DataServerProtocol.cpp

void DataServerProtocolCore(int index,BYTE head,BYTE* lpMsg,int size) // OK
{
case 0xD9:
switch(((lpMsg[0]==0xC1)?lpMsg[3]:lpMsg[4]))
{
case 0x07:
GDSaveTheGiftRecv((THEGIFT_GD_SAVE_DATA*)lpMsg); // Only add in the case 0xD9
break;
}
break;
}

void GDCharacterInfoRecv(SDHP_CHARACTER_INFO_RECV* lpMsg,int index) // OK
{
pMsg.TheGift = gQueryManager.GetAsInteger("TheGift"); // only add in is void
}


void GDSaveTheGiftRecv(THEGIFT_GD_SAVE_DATA* lpMsg) // OK
{
gQueryManager.ExecQuery("UPDATE Character SET TheGift = %d WHERE Name = '%s'",lpMsg->TheGift, lpMsg->Name);
gQueryManager.Close();
}

DataServerProtocol.h

struct SDHP_CHARACTER_INFO_SEND
{
BYTE TheGift; // only add in is struct
};


struct THEGIFT_GD_SAVE_DATA
{
PSBMSG_HEAD header;
WORD index;
char Name[11];
BYTE TheGift;
};

void GDSaveTheGiftRecv(THEGIFT_GD_SAVE_DATA* lpMsg);

QUERY SQL


USE MUONLINE
GO
alter table [Character] add [TheGift] int not null default(0)

GiftForNew.txt


//================================================== =================================
// Description: Gift set item with time for new player
// ----------------------------------------------------------------------------------
//================================================== =================================

//================================================== =================================
// Class SetID Level Luck Option Excellent Days
//================================================== =================================
0 2 9 1 7 3 1 //Dark Wizard
1 5 9 1 7 3 1 //Dark Knight
2 10 9 1 7 3 1 //Elf
3 15 9 1 7 3 1 //Magic Gladiator
4 5 9 1 7 3 1 //Dark Lord
5 39 9 1 7 3 1 //Summoner
6 59 9 1 7 3 1 //Rage Fighter
end

Créditos:
infinite