Browse Source

Changed many CStrings to Strings

release/0.19
JustinAJ 11 years ago
parent
commit
e8ceb1c317
  1. 223
      Jupiter/IRC_Client.cpp
  2. BIN
      Release/Jupiter.lib

223
Jupiter/IRC_Client.cpp

@ -31,6 +31,8 @@
Jupiter::INIFile _Config; Jupiter::INIFile _Config;
Jupiter::INIFile *Jupiter::IRC::Client::Config = &_Config; Jupiter::INIFile *Jupiter::IRC::Client::Config = &_Config;
template class JUPITER_API Jupiter::Reference_String<char>;
template class JUPITER_API Jupiter::String_Strict<char>;
template class JUPITER_API Jupiter::CString_Type<char>; template class JUPITER_API Jupiter::CString_Type<char>;
template class JUPITER_API Jupiter::ArrayList<Jupiter::IRC::Client::User>; template class JUPITER_API Jupiter::ArrayList<Jupiter::IRC::Client::User>;
template class JUPITER_API Jupiter::ArrayList<Jupiter::IRC::Client::Channel>; template class JUPITER_API Jupiter::ArrayList<Jupiter::IRC::Client::Channel>;
@ -40,33 +42,33 @@ struct JUPITER_API Jupiter::IRC::Client::Data
Jupiter::IRC::Client *iFace; Jupiter::IRC::Client *iFace;
Jupiter::Socket *sock; Jupiter::Socket *sock;
bool ssl; bool ssl;
Jupiter::CStringS SSLCertificate; Jupiter::StringS SSLCertificate;
Jupiter::CStringS SSLKey; Jupiter::StringS SSLKey;
Jupiter::CStringS saslAccount; Jupiter::StringS saslAccount;
Jupiter::CStringS saslPass; Jupiter::StringS saslPass;
int connectionStatus; int connectionStatus;
Jupiter::CStringS configSectionName; Jupiter::StringS configSectionName;
Jupiter::CStringS logFileName; Jupiter::CStringS logFileName;
Jupiter::CStringS buffer; Jupiter::ReferenceString buffer;
unsigned short serverPort; unsigned short serverPort;
Jupiter::CStringS serverHostname; Jupiter::CStringS serverHostname;
Jupiter::CStringS serverName; Jupiter::StringS serverName;
Jupiter::CStringS nickname; Jupiter::StringS nickname;
Jupiter::CStringS realName; Jupiter::StringS realName;
Jupiter::CStringS prefixModes = "ov"; Jupiter::StringS prefixModes = "ov";
Jupiter::CStringS prefixes = "@+"; Jupiter::StringS prefixes = "@+";
Jupiter::CStringS chanTypes = "#"; Jupiter::StringS chanTypes = "#";
Jupiter::CStringS modeA = "b"; Jupiter::StringS modeA = "b";
Jupiter::CStringS modeB = "k"; Jupiter::StringS modeB = "k";
Jupiter::CStringS modeC = "l"; Jupiter::StringS modeC = "l";
Jupiter::CStringS modeD = "psitnm"; Jupiter::StringS modeD = "psitnm";
Jupiter::ArrayList<Channel> channels; Jupiter::ArrayList<Channel> channels;
void delChannel(unsigned int index); void delChannel(unsigned int index);
void delChannel(const Jupiter::ReadableString &chan); void delChannel(const Jupiter::ReadableString &chan);
void addNamesToChannel(unsigned int channelIndex, Jupiter::ReadableString &names); void addNamesToChannel(unsigned int channelIndex, Jupiter::ReadableString &names);
size_t addChannel(const Jupiter::ReadableString &chan); size_t addChannel(const Jupiter::ReadableString &chan);
bool joinOnKick; bool joinOnKick;
Jupiter::CStringS autoPartMessage; Jupiter::StringS autoPartMessage;
time_t reconnectDelay; time_t reconnectDelay;
time_t reconnectTime; time_t reconnectTime;
int maxReconnectAttempts; int maxReconnectAttempts;
@ -92,20 +94,20 @@ Jupiter::IRC::Client::Data::Data(Jupiter::IRC::Client *interFace)
struct Jupiter::IRC::Client::User::Data struct Jupiter::IRC::Client::User::Data
{ {
unsigned int channelCount = 0; unsigned int channelCount = 0;
Jupiter::CStringS nickname; Jupiter::StringS nickname;
Jupiter::CStringS username; Jupiter::StringS username;
Jupiter::CStringS hostname; Jupiter::StringS hostname;
}; };
struct Jupiter::IRC::Client::Channel::User::Data struct Jupiter::IRC::Client::Channel::User::Data
{ {
Jupiter::IRC::Client::User *user; Jupiter::IRC::Client::User *user;
Jupiter::CStringS prefixes; Jupiter::StringS prefixes;
}; };
struct Jupiter::IRC::Client::Channel::Data struct Jupiter::IRC::Client::Channel::Data
{ {
Jupiter::CStringS channel; Jupiter::StringS channel;
Jupiter::ArrayList<Jupiter::IRC::Client::Channel::User> users; Jupiter::ArrayList<Jupiter::IRC::Client::Channel::User> users;
Jupiter::ReferenceString serverPrefixSetPtr; Jupiter::ReferenceString serverPrefixSetPtr;
int type; int type;
@ -159,7 +161,8 @@ Jupiter::IRC::Client::Client(const Jupiter::ReadableString &configSection)
if (Jupiter::IRC::Client::readConfigBool(STRING_LITERAL_AS_REFERENCE("PrintOutput"), true)) Jupiter::IRC::Client::data_->printOutput = stdout; if (Jupiter::IRC::Client::readConfigBool(STRING_LITERAL_AS_REFERENCE("PrintOutput"), true)) Jupiter::IRC::Client::data_->printOutput = stdout;
else Jupiter::IRC::Client::data_->printOutput = nullptr; else Jupiter::IRC::Client::data_->printOutput = nullptr;
if (Jupiter::IRC::Client::data_->logFileName.size() != 0) Jupiter::IRC::Client::data_->logFile = fopen(Jupiter::IRC::Client::data_->logFileName.c_str(), "a+b"); if (Jupiter::IRC::Client::data_->logFileName.size() != 0)
Jupiter::IRC::Client::data_->logFile = fopen(Jupiter::IRC::Client::data_->logFileName.c_str(), "a+b");
else Jupiter::IRC::Client::data_->logFile = nullptr; else Jupiter::IRC::Client::data_->logFile = nullptr;
if (Jupiter::IRC::Client::data_->ssl) if (Jupiter::IRC::Client::data_->ssl)
@ -354,9 +357,9 @@ void Jupiter::IRC::Client::setPrintOutput(FILE *f)
Jupiter::IRC::Client::data_->printOutput = f; Jupiter::IRC::Client::data_->printOutput = f;
} }
inline Jupiter::CStringS getSender(Jupiter::CStringS &line) inline Jupiter::ReferenceString getSender(const Jupiter::ReadableString &line)
{ {
return line.getWord(0, ":! "); return Jupiter::ReferenceString::getWord(line, 0, ":! ");
} }
int Jupiter::IRC::Client::getAccessLevel(const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick) const int Jupiter::IRC::Client::getAccessLevel(const Jupiter::ReadableString &chan, const Jupiter::ReadableString &nick) const
@ -380,7 +383,7 @@ int Jupiter::IRC::Client::getAccessLevel(const Jupiter::ReadableString &chan, co
void Jupiter::IRC::Client::send(const Jupiter::ReadableString &rawMessage) void Jupiter::IRC::Client::send(const Jupiter::ReadableString &rawMessage)
{ {
Jupiter::CStringS out = rawMessage; Jupiter::StringS out = rawMessage;
out += ENDL; out += ENDL;
Jupiter::IRC::Client::data_->sock->send(out); Jupiter::IRC::Client::data_->sock->send(out);
} }
@ -533,7 +536,7 @@ int Jupiter::IRC::Client::primaryHandler()
unsigned int totalLines = Jupiter::IRC::Client::data_->buffer.wordCount(ENDL); unsigned int totalLines = Jupiter::IRC::Client::data_->buffer.wordCount(ENDL);
for (unsigned int currentLine = 0; currentLine < totalLines; currentLine++) for (unsigned int currentLine = 0; currentLine < totalLines; currentLine++)
{ {
Jupiter::CStringS buff = Jupiter::IRC::Client::data_->buffer.getWord(currentLine, ENDL); Jupiter::ReferenceString buff = Jupiter::IRC::Client::data_->buffer.getWord(currentLine, ENDL);
if (buff.size() != 0) if (buff.size() != 0)
{ {
Jupiter::IRC::Client::writeToLogs(buff); Jupiter::IRC::Client::writeToLogs(buff);
@ -684,11 +687,11 @@ int Jupiter::IRC::Client::primaryHandler()
Jupiter::ReferenceString w4 = Jupiter::ReferenceString::getWord(buff, 3, WHITESPACE); Jupiter::ReferenceString w4 = Jupiter::ReferenceString::getWord(buff, 3, WHITESPACE);
if (w4.equals("LS")) if (w4.equals("LS"))
{ {
Jupiter::CStringS listParams = buff.gotoWord(4, WHITESPACE); Jupiter::ReferenceString listParams = buff.gotoWord(4, WHITESPACE);
if (listParams[0] == ':') listParams.shiftRight(1); if (listParams[0] == ':') listParams.shiftRight(1);
unsigned int len = listParams.wordCount(WHITESPACE); unsigned int len = listParams.wordCount(WHITESPACE);
Jupiter::CStringS curr; Jupiter::ReferenceString curr;
Jupiter::CStringL req = "CAP REQ :"; Jupiter::StringL req = "CAP REQ :";
bool sasl = false; bool sasl = false;
for (unsigned int i = 0; i < len; i++) for (unsigned int i = 0; i < len; i++)
{ {
@ -709,11 +712,9 @@ int Jupiter::IRC::Client::primaryHandler()
{ {
req -= 1; // Trim off the extra space byte. req -= 1; // Trim off the extra space byte.
req += ENDL; req += ENDL;
Jupiter::IRC::Client::data_->sock->send(req.c_str()); Jupiter::IRC::Client::data_->sock->send(req);
if (sasl) if (sasl)
{
Jupiter::IRC::Client::data_->sock->send("AUTHENTICATE PLAIN" ENDL); Jupiter::IRC::Client::data_->sock->send("AUTHENTICATE PLAIN" ENDL);
}
} }
if (!sasl) if (!sasl)
{ {
@ -807,52 +808,50 @@ int Jupiter::IRC::Client::primaryHandler()
{ {
case IRC_RPL_ISUPPORT: // 005 case IRC_RPL_ISUPPORT: // 005
{ {
const char *ptr = strstr(buff.c_str(), "PREFIX=("); size_t pos = buff.find(STRING_LITERAL_AS_REFERENCE("PREFIX=("));
if (ptr != nullptr) if (pos != Jupiter::INVALID_INDEX)
{ {
ptr += 8; Jupiter::ReferenceString ref = Jupiter::ReferenceString::substring(buff, pos + 8);
int poff = findSymbol(ptr, ')', 0); Jupiter::IRC::Client::data_->prefixModes = Jupiter::ReferenceString::getWord(ref, 0, ")");
Jupiter::IRC::Client::data_->prefixModes = Jupiter::ReferenceString::getWord(ptr, 0, ")"); ref.shiftRight(ref.find(')'));
ptr += poff + 1; Jupiter::IRC::Client::data_->prefixes = Jupiter::ReferenceString::getWord(ref, 0, " " ENDL);
Jupiter::IRC::Client::data_->prefixes = Jupiter::ReferenceString::getWord(ptr, 0, " " ENDL);
ptr = nullptr;
} }
ptr = strstr(buff.c_str(), "CHANMODES="); pos = buff.find(STRING_LITERAL_AS_REFERENCE("CHANMODES="));
if (ptr != nullptr) if (pos != Jupiter::INVALID_INDEX)
{ {
ptr += 10; Jupiter::ReferenceString ref = Jupiter::ReferenceString::substring(buff, pos + 10);
int pos = findSymbol(ptr, ',', 0); ref = ref.getWord(0, " ");
if (pos >= 0) size_t pos2 = ref.find(',', 0);
if (pos != INVALID_INDEX)
{ {
Jupiter::IRC::Client::data_->modeA = Jupiter::ReferenceString::getWord(ptr, 0, ", "); Jupiter::IRC::Client::data_->modeA = ref.getWord(0, ", ");
ptr += pos + 1; ref.shiftRight(pos + 1);
pos = findSymbol(ptr, ',', 0); pos2 = ref.find(',', 0);
if (pos >= 0) if (pos != INVALID_INDEX)
{ {
Jupiter::IRC::Client::data_->modeB = Jupiter::ReferenceString::getWord(ptr, 0, ", "); Jupiter::IRC::Client::data_->modeB = ref.getWord(0, ", ");
ptr += pos + 1; ref.shiftRight(pos + 1);
pos = findSymbol(ptr, ',', 0); pos2 = ref.find(',', 0);
if (pos >= 0) if (pos != INVALID_INDEX)
{ {
Jupiter::IRC::Client::data_->modeC = Jupiter::ReferenceString::getWord(ptr, 0, ", "); Jupiter::IRC::Client::data_->modeC = ref.getWord(0, ", ");
ptr += pos + 1; ref.shiftRight(pos + 1);
pos = strcspn(ptr, " "); Jupiter::IRC::Client::data_->modeD = ref.getWord(0, ", ");
if (pos >= 0) Jupiter::IRC::Client::data_->modeD = Jupiter::ReferenceString::getWord(ptr, 0, ", ");
} }
} }
} }
} }
ptr = strstr(buff.c_str(), "CHANTYPES="); pos = buff.find(STRING_LITERAL_AS_REFERENCE("CHANTYPES="));
if (ptr != nullptr) if (pos != Jupiter::INVALID_INDEX)
{ {
ptr += 10; Jupiter::ReferenceString ref = Jupiter::ReferenceString::substring(buff, pos + 10);
Jupiter::IRC::Client::data_->chanTypes = Jupiter::ReferenceString::getWord(ptr, 0, " "); Jupiter::IRC::Client::data_->chanTypes = ref.getWord(0, " ");
} }
} }
break; break;
case IRC_RPL_LUSERCLIENT: // 251 case IRC_RPL_LUSERCLIENT: // 251
{ {
Jupiter::CStringL key = "RawData."; Jupiter::StringL key = "RawData.";
size_t offset; size_t offset;
unsigned int i = 1; unsigned int i = 1;
@ -893,10 +892,10 @@ int Jupiter::IRC::Client::primaryHandler()
Jupiter::ReferenceString chan = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE); Jupiter::ReferenceString chan = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE);
if (chan.size() != 0) if (chan.size() != 0)
{ {
Jupiter::CStringS nick = getSender(buff); Jupiter::ReferenceString nick = getSender(buff);
if (nick.size() != 0) if (nick.size() != 0)
{ {
Jupiter::ReferenceString premessage = buff.c_str() + findSymbol(buff.c_str(), ':', 1) + 1; Jupiter::ReferenceString premessage = Jupiter::ReferenceString::substring(buff, buff.find(':', 1) + 1);
if (premessage[0] == '\001') //CTCP (ACTIONs are included) if (premessage[0] == '\001') //CTCP (ACTIONs are included)
{ {
Jupiter::ReferenceString rawmessage(premessage.ptr() + 1, premessage.size() - 1); Jupiter::ReferenceString rawmessage(premessage.ptr() + 1, premessage.size() - 1);
@ -913,7 +912,7 @@ int Jupiter::IRC::Client::primaryHandler()
} }
else else
{ {
Jupiter::CStringL response = "NOTICE "; Jupiter::StringL response = "NOTICE ";
response += nick; response += nick;
response += " :" IRCCTCP; response += " :" IRCCTCP;
response += command; response += command;
@ -943,7 +942,7 @@ int Jupiter::IRC::Client::primaryHandler()
} }
else else
{ {
Jupiter::CStringS message = premessage; Jupiter::ReferenceString message = premessage;
this->OnChat(chan, nick, message); this->OnChat(chan, nick, message);
for (size_t i = 0; i < Jupiter::plugins->size(); i++) for (size_t i = 0; i < Jupiter::plugins->size(); i++)
Jupiter::plugins->get(i)->OnChat(this, chan, nick, message); Jupiter::plugins->get(i)->OnChat(this, chan, nick, message);
@ -956,11 +955,11 @@ int Jupiter::IRC::Client::primaryHandler()
Jupiter::ReferenceString chan = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE); Jupiter::ReferenceString chan = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE);
if (chan.size() != 0) if (chan.size() != 0)
{ {
int pos = findSymbol(buff.c_str(), '!', 0); size_t pos = buff.find('!', 0);
auto message = buff.substring(findSymbol(buff.c_str(), ':', 1) + 1, buff.size()); auto message = Jupiter::ReferenceString::substring(buff, buff.find(':', 1) + 1, buff.size());
if (pos >= 0 && strcspn(buff.c_str(), "!") < strcspn(buff.c_str(), " ")) if (pos < buff.find(' '))
{ {
auto nick = buff.substring(1, pos); auto nick = Jupiter::ReferenceString::substring(buff, 1, pos);
this->OnNotice(chan, nick, message); this->OnNotice(chan, nick, message);
for (size_t i = 0; i < Jupiter::plugins->size(); i++) for (size_t i = 0; i < Jupiter::plugins->size(); i++)
Jupiter::plugins->get(i)->OnNotice(this, chan, nick, message); Jupiter::plugins->get(i)->OnNotice(this, chan, nick, message);
@ -980,9 +979,8 @@ int Jupiter::IRC::Client::primaryHandler()
else if (w2.equalsi("NICK")) else if (w2.equalsi("NICK"))
{ {
auto nick = getSender(buff); auto nick = getSender(buff);
const char *tnewnick = buff.c_str() + findSymbol(buff.c_str(), ' ', 1) + 1; Jupiter::ReferenceString newnick = Jupiter::ReferenceString::substring(buff, buff.find(' ', 1) + 1);
if (*tnewnick == ':') tnewnick++; if (newnick.size() != 0 && newnick[0] == ':') newnick.shiftRight(1);
Jupiter::CStringS newnick = tnewnick;
if (nick.equalsi(Jupiter::IRC::Client::data_->nickname)) if (nick.equalsi(Jupiter::IRC::Client::data_->nickname))
{ {
Jupiter::IRC::Client::data_->nickname = newnick; Jupiter::IRC::Client::data_->nickname = newnick;
@ -1035,8 +1033,10 @@ int Jupiter::IRC::Client::primaryHandler()
{ {
Jupiter::IRC::Client::User *user = Jupiter::IRC::Client::data_->users.get(userIndex); Jupiter::IRC::Client::User *user = Jupiter::IRC::Client::data_->users.get(userIndex);
Jupiter::IRC::Client::data_->channels.get(i)->delUser(nick); Jupiter::IRC::Client::data_->channels.get(i)->delUser(nick);
int pos = findSymbol(buff.c_str(), ':', 1); Jupiter::ReferenceString reason;
Jupiter::CStringS reason = buff.c_str() + pos + 1; size_t pos = buff.find(':', 1);
if (pos != Jupiter::INVALID_INDEX)
reason = Jupiter::ReferenceString::substring(buff, pos + 1);
this->OnPart(chan, nick, reason); this->OnPart(chan, nick, reason);
for (i = Jupiter::plugins->size() - 1; i >= 0; i--) Jupiter::plugins->get(i)->OnPart(this, chan, nick, reason); for (i = Jupiter::plugins->size() - 1; i >= 0; i--) Jupiter::plugins->get(i)->OnPart(this, chan, nick, reason);
if (nick.equalsi(Jupiter::IRC::Client::data_->nickname)) Jupiter::IRC::Client::data_->delChannel(chan); if (nick.equalsi(Jupiter::IRC::Client::data_->nickname)) Jupiter::IRC::Client::data_->delChannel(chan);
@ -1051,7 +1051,7 @@ int Jupiter::IRC::Client::primaryHandler()
Jupiter::ReferenceString chan = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE); Jupiter::ReferenceString chan = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE);
if (chan.size() != 0) if (chan.size() != 0)
{ {
Jupiter::CStringS kicker = getSender(buff); Jupiter::ReferenceString kicker = getSender(buff);
if (kicker.size() != 0) if (kicker.size() != 0)
{ {
Jupiter::ReferenceString kicked = Jupiter::ReferenceString::getWord(buff, 3, WHITESPACE); Jupiter::ReferenceString kicked = Jupiter::ReferenceString::getWord(buff, 3, WHITESPACE);
@ -1065,9 +1065,10 @@ int Jupiter::IRC::Client::primaryHandler()
{ {
Jupiter::IRC::Client::User *user = Jupiter::IRC::Client::data_->users.get(userIndex); Jupiter::IRC::Client::User *user = Jupiter::IRC::Client::data_->users.get(userIndex);
Jupiter::IRC::Client::data_->channels.get(i)->delUser(kicked); Jupiter::IRC::Client::data_->channels.get(i)->delUser(kicked);
int pos = findSymbol(buff.c_str(), ':', 1); size_t pos = buff.find(':', 1);
Jupiter::CStringS reason; Jupiter::ReferenceString reason;
if (pos >= 0) reason += buff.c_str() + pos + 1; if (pos != Jupiter::INVALID_INDEX)
reason = Jupiter::ReferenceString::substring(buff, pos + 1);
this->OnKick(chan, kicker, kicked, reason); this->OnKick(chan, kicker, kicked, reason);
for (i = Jupiter::plugins->size() - 1; i >= 0; i--) Jupiter::plugins->get(i)->OnKick(this, chan, kicker, kicked, reason); for (i = Jupiter::plugins->size() - 1; i >= 0; i--) Jupiter::plugins->get(i)->OnKick(this, chan, kicker, kicked, reason);
if (kicked.equalsi(Jupiter::IRC::Client::data_->nickname)) if (kicked.equalsi(Jupiter::IRC::Client::data_->nickname))
@ -1084,8 +1085,8 @@ int Jupiter::IRC::Client::primaryHandler()
} }
else if (w2.equalsi("QUIT")) else if (w2.equalsi("QUIT"))
{ {
Jupiter::CStringS nick = getSender(buff); Jupiter::ReferenceString nick = getSender(buff);
Jupiter::CStringS message = buff.substring(findSymbol(buff.c_str(), ':', 1) + 1, buff.size()); Jupiter::ReferenceString message = Jupiter::ReferenceString::substring(buff, buff.find(':', 1) + 1);
int userIndex = Jupiter::IRC::Client::getUserIndex(nick); int userIndex = Jupiter::IRC::Client::getUserIndex(nick);
if (userIndex >= 0) if (userIndex >= 0)
{ {
@ -1100,9 +1101,9 @@ int Jupiter::IRC::Client::primaryHandler()
} }
else if (w2.equalsi("INVITE")) else if (w2.equalsi("INVITE"))
{ {
Jupiter::CStringS inviter = getSender(buff); Jupiter::ReferenceString inviter = getSender(buff);
Jupiter::ReferenceString invited = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE); Jupiter::ReferenceString invited = Jupiter::ReferenceString::getWord(buff, 2, WHITESPACE);
Jupiter::CStringS chan = buff.c_str() + findSymbol(buff.c_str(), ':', 1) + 1; Jupiter::ReferenceString chan = Jupiter::ReferenceString::substring(buff, buff.find(':', 1) + 1);
this->OnInvite(chan, inviter, invited); this->OnInvite(chan, inviter, invited);
for (size_t i = 0; i < Jupiter::plugins->size(); i++) for (size_t i = 0; i < Jupiter::plugins->size(); i++)
Jupiter::plugins->get(i)->OnInvite(this, chan, inviter, invited); Jupiter::plugins->get(i)->OnInvite(this, chan, inviter, invited);
@ -1117,24 +1118,25 @@ int Jupiter::IRC::Client::primaryHandler()
auto nick = getSender(buff); auto nick = getSender(buff);
if (nick.size() != 0) if (nick.size() != 0)
{ {
const char *modestring = buff.c_str() + findSymbol(buff.c_str(), ' ', 2) + 1; Jupiter::ReferenceString modestring = Jupiter::ReferenceString::substring(buff, buff.find(' ', 2) + 1);
if (wordCount(modestring) > 1) if (modestring.wordCount(" ") > 1)
{ {
char *modes = getWord(modestring, 0); Jupiter::ReferenceString modes = modestring.getWord(0, " ");
if (modes != nullptr) if (modes.isEmpty() == false)
{ {
const char *params = modestring + findSymbol(modestring, ' ', 0) + 1; modestring.shiftRight(modestring.find(' ') + 1);
char *tword; Jupiter::ReferenceString tword;
unsigned char g = 0; unsigned char g = 0;
char symb = 0; char symb = 0;
for (uint8_t z = 0; modes[z] != 0; z++) for (uint8_t z = 0; modes[z] != 0; z++)
{ {
if (modes[z] == '+' || modes[z] == '-') symb = modes[z]; if (modes[z] == '+' || modes[z] == '-')
else if (Jupiter::IRC::Client::data_->prefixModes.contains(modes[z])) symb = modes[z];
else if (Jupiter::IRC::Client::data_->prefixModes.contains(modes[z])) // user prefix mode
{ {
tword = getWord(params, g); tword = modestring.getWord(g, " ");
if (tword != nullptr) if (tword.isEmpty() == false)
{ {
Jupiter::IRC::Client::Channel *channel; Jupiter::IRC::Client::Channel *channel;
for (unsigned int channelIndex = 0; channelIndex < Jupiter::IRC::Client::data_->channels.size(); channelIndex++) for (unsigned int channelIndex = 0; channelIndex < Jupiter::IRC::Client::data_->channels.size(); channelIndex++)
@ -1142,7 +1144,8 @@ int Jupiter::IRC::Client::primaryHandler()
channel = Jupiter::IRC::Client::data_->channels.get(channelIndex); channel = Jupiter::IRC::Client::data_->channels.get(channelIndex);
if (channel->getName().equalsi(chan)) if (channel->getName().equalsi(chan))
{ {
if (symb == '+') channel->addUserPrefix(Jupiter::ReferenceString(tword), Jupiter::IRC::Client::data_->prefixes[Jupiter::IRC::Client::data_->prefixModes.find(modes[z])]); if (symb == '+')
channel->addUserPrefix(Jupiter::ReferenceString(tword), Jupiter::IRC::Client::data_->prefixes[Jupiter::IRC::Client::data_->prefixModes.find(modes[z])]);
else channel->delUserPrefix(Jupiter::ReferenceString(tword), Jupiter::IRC::Client::data_->prefixes[Jupiter::IRC::Client::data_->prefixModes.find(modes[z])]); else channel->delUserPrefix(Jupiter::ReferenceString(tword), Jupiter::IRC::Client::data_->prefixes[Jupiter::IRC::Client::data_->prefixModes.find(modes[z])]);
break; break;
} }
@ -1150,20 +1153,19 @@ int Jupiter::IRC::Client::primaryHandler()
} }
g++; g++;
} }
else else if (Jupiter::IRC::Client::data_->modeA.contains(modes[z])) // mode type A
{ g++;
if (Jupiter::IRC::Client::data_->modeA.contains(modes[z])) g++; else if (Jupiter::IRC::Client::data_->modeB.contains(modes[z])) // mode type B
else if (Jupiter::IRC::Client::data_->modeB.contains(modes[z])) g++; g++;
else if (Jupiter::IRC::Client::data_->modeC.contains(modes[z]) && symb == '+') g++; else if (Jupiter::IRC::Client::data_->modeC.contains(modes[z]) && symb == '+') // mode type C (with parameter)
} g++;
// else; // mode type D
} }
free(modes);
} }
} }
Jupiter::CStringS modeString = modestring; this->OnMode(chan, nick, modestring);
this->OnMode(chan, nick, modeString);
for (size_t i = 0; i < Jupiter::plugins->size(); i++) for (size_t i = 0; i < Jupiter::plugins->size(); i++)
Jupiter::plugins->get(i)->OnMode(this, chan, nick, modeString); Jupiter::plugins->get(i)->OnMode(this, chan, nick, modestring);
} }
} }
} }
@ -1203,11 +1205,12 @@ int Jupiter::IRC::Client::primaryHandler()
} }
else if (w1.equals("NICK")) else if (w1.equals("NICK"))
{ {
if (w2.size() != 0) Jupiter::IRC::Client::data_->nickname = w2; if (w2.isEmpty() == false)
Jupiter::IRC::Client::data_->nickname = w2;
} }
else if (w1.equals("ERROR")) else if (w1.equals("ERROR"))
{ {
Jupiter::CStringS reason = buff.c_str() + strcspn(buff.c_str(), ":") + 1; Jupiter::ReferenceString reason = Jupiter::ReferenceString::substring(buff, buff.find(':') + 1);
this->OnError(reason); this->OnError(reason);
for (size_t i = 0; i < Jupiter::plugins->size(); i++) for (size_t i = 0; i < Jupiter::plugins->size(); i++)
Jupiter::plugins->get(i)->OnError(this, reason); Jupiter::plugins->get(i)->OnError(this, reason);
@ -1442,7 +1445,7 @@ void Jupiter::IRC::Client::Data::addNamesToChannel(unsigned int index, Jupiter::
t = Jupiter::ReferenceString::getWord(names, i, " "); t = Jupiter::ReferenceString::getWord(names, i, " ");
if (t.size() != 0) if (t.size() != 0)
{ {
offset = t.span(Jupiter::IRC::Client::Data::prefixes.c_str()); offset = t.span(Jupiter::IRC::Client::Data::prefixes);
t.shiftRight(offset); t.shiftRight(offset);
Jupiter::IRC::Client::User *user = Jupiter::IRC::Client::Data::findUserOrAdd(t); Jupiter::IRC::Client::User *user = Jupiter::IRC::Client::Data::findUserOrAdd(t);
t.shiftLeft(offset); t.shiftLeft(offset);
@ -1565,7 +1568,7 @@ Jupiter::IRC::Client::Channel::Channel(const Jupiter::ReadableString &channelNam
Jupiter::IRC::Client::Channel::~Channel() Jupiter::IRC::Client::Channel::~Channel()
{ {
while (Jupiter::IRC::Client::Channel::data_->users.size() != 0) delete Jupiter::IRC::Client::Channel::data_->users.remove(0); Jupiter::IRC::Client::Channel::data_->users.emptyAndDelete();
delete Jupiter::IRC::Client::Channel::data_; delete Jupiter::IRC::Client::Channel::data_;
} }
@ -1673,7 +1676,7 @@ char Jupiter::IRC::Client::Channel::getUserPrefix(unsigned int index) const
{ {
if (index < Jupiter::IRC::Client::Channel::data_->users.size()) if (index < Jupiter::IRC::Client::Channel::data_->users.size())
for (unsigned char i = 0; Jupiter::IRC::Client::Channel::data_->serverPrefixSetPtr[i]; i++) for (unsigned char i = 0; Jupiter::IRC::Client::Channel::data_->serverPrefixSetPtr[i]; i++)
if (containsSymbol(Jupiter::IRC::Client::Channel::data_->users.get(index)->data_->prefixes.c_str(), Jupiter::IRC::Client::Channel::data_->serverPrefixSetPtr[i])) if (Jupiter::IRC::Client::Channel::data_->users.get(index)->data_->prefixes.contains(Jupiter::IRC::Client::Channel::data_->serverPrefixSetPtr[i]))
return Jupiter::IRC::Client::Channel::data_->serverPrefixSetPtr[i]; return Jupiter::IRC::Client::Channel::data_->serverPrefixSetPtr[i];
return 0; return 0;
} }

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save