forked from Mirrors/openclonk
Save IRC clients joined channels
parent
c8bc3f8621
commit
9e1bff2e17
|
@ -537,6 +537,8 @@ void C4Application::Clear()
|
|||
// stop timer
|
||||
Remove(pGameTimer);
|
||||
delete pGameTimer; pGameTimer = NULL;
|
||||
// quit irc
|
||||
IRCClient.Close();
|
||||
// close system group (System.ocg)
|
||||
SystemGroup.Close();
|
||||
// Log
|
||||
|
|
|
@ -530,6 +530,7 @@ void C4ChatControl::OnConnectBtn(C4GUI::Control *btn)
|
|||
if (sChannel.getLength() && C4InVal::ValidateString(sChannel, C4InVal::VAL_IRCChannel))
|
||||
{
|
||||
GetScreen()->ShowErrorMessage(LoadResStr("IDS_ERR_INVALIDCHANNELNAME"));
|
||||
pEdtLoginChannel->SetText(sChannel.getData(), false);
|
||||
GetDlg()->SetFocus(pEdtLoginChannel, false);
|
||||
return;
|
||||
}
|
||||
|
@ -800,6 +801,8 @@ void C4ChatControl::UpdateTitle()
|
|||
sTitle.Take(std::move(sNewTitle));
|
||||
if (pTitleChangeBC) pTitleChangeBC->OnOK(sTitle);
|
||||
}
|
||||
// reload the channel join string from config to fetch C4Network2IRCClient's changes
|
||||
pEdtLoginChannel->SetText(Config.IRC.Channel, false);
|
||||
}
|
||||
|
||||
bool C4ChatControl::DlgEnter()
|
||||
|
@ -1011,7 +1014,7 @@ void C4ChatDlg::StopChat()
|
|||
{
|
||||
if (!pInstance) return;
|
||||
pInstance->Close(false);
|
||||
// 2do: Quit IRC
|
||||
Application.IRCClient.Close();
|
||||
}
|
||||
|
||||
bool C4ChatDlg::ToggleChat()
|
||||
|
|
|
@ -132,11 +132,28 @@ namespace C4InVal
|
|||
break;
|
||||
|
||||
case VAL_IRCChannel: // IRC channel name
|
||||
if (rsString.getLength() > 32) { fValid = false; rsString.SetLength(32); }
|
||||
else if (rsString.getLength() < 2) { fValid = false; rsString.Copy("#clonken"); }
|
||||
else if (*rsString.getData() != '#' && *rsString.getData() != '+') { fValid = false; *rsString.getMData() = '#'; }
|
||||
if (rsString.ReplaceChar(' ', '_')) fValid = false;
|
||||
{ // needed for the vector
|
||||
std::vector<StdStrBuf> chans;
|
||||
StdStrBuf SplitPart;
|
||||
while(rsString.SplitAtChar(',', &SplitPart)) // Split
|
||||
{
|
||||
chans.push_back(rsString);
|
||||
rsString.Copy(SplitPart);
|
||||
}
|
||||
chans.push_back(rsString);
|
||||
rsString.Clear();
|
||||
for(std::vector<StdStrBuf>::iterator it = chans.begin(); it < chans.end(); ++it) // Reassemble clean
|
||||
{
|
||||
if (it->getLength() > 32) { fValid = false; it->SetLength(32); }
|
||||
else if (it->getLength() < 2) { fValid = false; it->Clear(); }
|
||||
else if (*it->getData() != '#' && *it->getData() != '+') { fValid = false; it->InsertChar('#', 0); }
|
||||
if (it->ReplaceChar(' ', '_')) fValid = false;
|
||||
rsString.Append(*it);
|
||||
if(it+1 < chans.end() && it->getLength() > 0) rsString.Append(",");
|
||||
}
|
||||
if(rsString.getLength() < 2) rsString.Copy("#openclonk");
|
||||
break;
|
||||
}
|
||||
|
||||
case VAL_Comment: // comment - just limit length
|
||||
if (rsString.getLength() > C4MaxComment) { fValid = false; rsString.SetLength(C4MaxComment); }
|
||||
|
|
|
@ -182,6 +182,7 @@ void C4Network2IRCChannel::ClearUsers()
|
|||
|
||||
|
||||
// *** C4Network2IRCClient
|
||||
// Created statically in C4Application.cpp, refer by &Application.IRCClient
|
||||
|
||||
C4Network2IRCClient::C4Network2IRCClient()
|
||||
: fConnecting(false), fConnected(false),
|
||||
|
@ -343,7 +344,26 @@ bool C4Network2IRCClient::Close()
|
|||
{
|
||||
// Close network
|
||||
C4NetIOTCP::Close();
|
||||
// Clear channels
|
||||
// Save & Clear channels
|
||||
if(pChannels) // Don't override empty
|
||||
{
|
||||
// It's somewhat weird to loop backward through a singly linked list, but it's necessary to keep the order
|
||||
StdStrBuf chanstr;
|
||||
C4Network2IRCChannel * pChan = pChannels;
|
||||
while(pChan->Next)
|
||||
pChan = pChan->Next;
|
||||
chanstr.Append(pChan->getName());
|
||||
while (pChan != pChannels)
|
||||
{
|
||||
C4Network2IRCChannel * pChanPrev = pChannels;
|
||||
while(pChanPrev->Next != pChan)
|
||||
pChanPrev = pChanPrev->Next;
|
||||
pChan = pChanPrev;
|
||||
chanstr.Append(",");
|
||||
chanstr.Append(pChan->getName());
|
||||
}
|
||||
strncpy(Config.IRC.Channel, chanstr.getData(), sizeof(Config.IRC.Channel)-1);
|
||||
}
|
||||
while (pChannels)
|
||||
DeleteChannel(pChannels);
|
||||
// Clear log
|
||||
|
@ -819,4 +839,3 @@ void C4Network2IRCClient::DeleteChannel(C4Network2IRCChannel *pChannel)
|
|||
// Delete
|
||||
delete pChannel;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue