Bom, recentemente eu decidi abandonar completamente o uso de Threads em meus projetos de Mu Online, devido a isso, tive que atualizar muitos códigos. Então vou compartilhar um código simples para implementar notícias no servidor.
News.h
Código:
struct NEWS{
public:
NEWS();
virtual ~NEWS();
void Load();
void Proc();
private:
int Switch;
int Session;
int Index;
int Line;
long Interval;
char Messages[100][3][220];
unsigned long TimerProc;
};
extern NEWS Noticias;
News.cpp
Código:
NEWS Noticias;
NEWS::NEWS() : Index(0), Line(0), TimerProc(0)
{
}
NEWS::~NEWS()
{
for (int i = 0; i < this->Session; i++)
{
delete[] this->Messages[i];
}
delete[] this->Messages;
}
void NEWS::Load()
{
this->Switch = GetPrivateProfileInt("Configurações", "Ativar", 0, "..\\Data\\News.txt");
this->Session = GetPrivateProfileInt("Configurações", "Sessões", 0, "..\\Data\\News.txt");
this->Interval = GetPrivateProfileInt("Configurações", "Intervalo", 30, "..\\Data\\News.txt") * 60;
for (int i = 0; i < this->Session; i++)
{
char secao[220];
StringCbPrintf(secao, MAX_BUFFER_STRING, _T("Notícia %02d"), i + 1);
for (int j = 0; j < 3; j++)
{
char chave[220];
StringCbPrintf(chave, MAX_BUFFER_STRING, _T("Linha %02d"), j + 1);
GetPrivateProfileString(secao, chave, "Notícia Teste", this->Messages[i][j], 220, "..\\Data\\News.txt");
}
}
}
void NEWS::Proc()
{
if (this->Switch > 0 && this->Session > 0)
{
if (this->TimerProc >= this->Interval)
{
if (strlen(this->Messages[this->Index][this->Line]) > 0)
{
ServerAnnounce(this->Messages[this->Index][this->Line]);
}
if (strlen(this->Messages[this->Index][this->Line + 1]) > 0)
{
ServerAnnounce(this->Messages[this->Index][this->Line + 1]);
}
if (strlen(this->Messages[this->Index][this->Line + 2]) > 0)
{
ServerAnnounce(this->Messages[this->Index][this->Line + 2]);
}
this->Index = (this->Index + 1) % this->Session;
this->TimerProc = 0;
}
else
{
this->TimerProc++;
}
}
}