summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bouncer/core.h16
-rw-r--r--bouncer/ircserver.cpp13
-rw-r--r--bouncer/mobileclient.cpp14
-rw-r--r--bouncer/window.cpp122
4 files changed, 125 insertions, 40 deletions
diff --git a/bouncer/core.h b/bouncer/core.h
index d7d54f3..8817b77 100644
--- a/bouncer/core.h
+++ b/bouncer/core.h
@@ -67,6 +67,7 @@ public:
virtual void handleUserClosed();
void pushMessage(const char *str);
+ void notifyWindowRename();
};
class StatusWindow : public Window {
@@ -303,13 +304,18 @@ private:
};
struct IRCNetworkConfig {
- char hostname[512];
- char nickname[128];
- char username[128];
- char realname[128];
- char password[128];
+ std::string hostname, username, realname;
+ std::string nickname, altNick;
+ std::string password;
int port;
bool useTls;
+
+ IRCNetworkConfig() {
+ username = "user";
+ realname = "VulpIRC User";
+ port = 6667;
+ useTls = false;
+ }
};
class IRCServer : public Server {
diff --git a/bouncer/ircserver.cpp b/bouncer/ircserver.cpp
index 63d5c90..8279484 100644
--- a/bouncer/ircserver.cpp
+++ b/bouncer/ircserver.cpp
@@ -27,7 +27,9 @@ void IRCServer::attachedToCore() {
void IRCServer::connect() {
status.pushMessage("Connecting...");
- Server::connect(config.hostname, config.port, config.useTls);
+ Server::connect(
+ config.hostname.c_str(), config.port,
+ config.useTls);
}
@@ -92,13 +94,16 @@ void IRCServer::connectedEvent() {
char buf[2048];
- if (strlen(config.password) > 0) {
- sprintf(buf, "PASS %s", config.password);
+ if (config.password.size() > 0) {
+ sprintf(buf, "PASS %s", config.password.c_str());
sendLine(buf);
}
sprintf(buf, "USER %s 0 * :%s\r\nNICK %s",
- config.username, config.realname, config.nickname);
+ config.username.c_str(),
+ config.realname.c_str(),
+ config.nickname.c_str());
+
sendLine(buf);
}
void IRCServer::disconnectedEvent() {
diff --git a/bouncer/mobileclient.cpp b/bouncer/mobileclient.cpp
index 65ddefe..0dbc35a 100644
--- a/bouncer/mobileclient.cpp
+++ b/bouncer/mobileclient.cpp
@@ -67,21 +67,9 @@ void MobileClient::handleDebugCommand(char *line, int size) {
} else if (strcmp(line, "quit") == 0) {
bouncer->quitFlag = true;
- } else if (strncmp(&line[1], "ddsrv ", 6) == 0) {
+ } else if (strcmp(line, "addsrv") == 0) {
IRCServer *srv = new IRCServer(bouncer);
- strcpy(srv->config.hostname, &line[7]);
- srv->config.useTls = (line[0] == 's');
- srv->config.port = (line[0] == 's') ? 1191 : 6667;
- strcpy(srv->config.nickname, "Ninjifox");
- strcpy(srv->config.username, "boop");
- strcpy(srv->config.realname, "boop");
- strcpy(srv->config.password, "");
bouncer->registerServer(srv);
-
- Buffer pkt;
- pkt.writeStr("Your wish is my command!");
- for (int i = 0; i < bouncer->clientCount; i++)
- bouncer->clients[i]->sendPacket(Packet::B2C_STATUS, pkt);
}
}
diff --git a/bouncer/window.cpp b/bouncer/window.cpp
index 98f0418..88e8247 100644
--- a/bouncer/window.cpp
+++ b/bouncer/window.cpp
@@ -20,6 +20,15 @@ void Window::syncStateForClient(Buffer &output) {
}
}
+void Window::notifyWindowRename() {
+ Buffer packet;
+ packet.writeU32(id);
+ packet.writeStr(getTitle());
+
+ core->sendToClients(
+ Packet::B2C_WINDOW_RENAME, packet);
+}
+
void Window::pushMessage(const char *str) {
messages.push_back(str);
@@ -53,7 +62,10 @@ StatusWindow::StatusWindow(IRCServer *_server) :
}
const char *StatusWindow::getTitle() const {
- return server->config.hostname;
+ if (server->config.hostname.size() == 0)
+ return "<New Server>";
+ else
+ return server->config.hostname.c_str();
}
int StatusWindow::getType() const {
@@ -61,21 +73,100 @@ int StatusWindow::getType() const {
}
void StatusWindow::handleUserInput(const char *str) {
+ char buf[1024];
+
if (str[0] == '/') {
// moof
if (strcmp(str, "/connect") == 0) {
- server->connect();
+
+ // Check if we have everything needed...
+ if (server->config.nickname.size() == 0) {
+ pushMessage("Use /defaultnick <name> to set a nickname");
+ } else if (server->config.altNick.size() == 0) {
+ pushMessage("Use /altnick <name> to set an alternate nickname");
+ } else if (server->config.hostname.size() == 0) {
+ pushMessage("Use /server <name> to set an IRC server to connect to");
+ } else {
+ server->connect();
+ }
+
} else if (strcmp(str, "/disconnect") == 0) {
server->close();
- } else if (strncmp(str, "/password ", 10) == 0) {
- pushMessage("Password set.");
-
- // This is ugly, ugh
- strncpy(
- server->config.password,
- &str[10],
- sizeof(server->config.password));
- server->config.password[sizeof(server->config.password) - 1] = 0;
+
+ } else if (strncmp(str, "/defaultnick ", 13) == 0) {
+ server->config.nickname = &str[13];
+
+ // generate a default altnick if we don't have one already
+ if (server->config.altNick.size() == 0) {
+ server->config.altNick = server->config.nickname + "_";
+ }
+
+ snprintf(buf, sizeof(buf),
+ "Default nickname changed to: %s",
+ server->config.nickname.c_str());
+ pushMessage(buf);
+
+ } else if (strncmp(str, "/altnick ", 9) == 0) {
+ server->config.altNick = &str[9];
+
+ snprintf(buf, sizeof(buf),
+ "Alternate nickname changed to: %s",
+ server->config.altNick.c_str());
+ pushMessage(buf);
+
+ } else if (strncmp(str, "/server ", 8) == 0) {
+ server->config.hostname = &str[8];
+
+ snprintf(buf, sizeof(buf),
+ "Server address changed to: %s",
+ server->config.hostname.c_str());
+ pushMessage(buf);
+
+ notifyWindowRename();
+
+ } else if (strncmp(str, "/port ", 6) == 0) {
+ const char *p = &str[6];
+ if (*p == '+') {
+ server->config.useTls = true;
+ ++p;
+ } else {
+ server->config.useTls = false;
+ }
+ server->config.port = atoi(p);
+
+ snprintf(buf, sizeof(buf),
+ "Server port changed to %d, TLS %s",
+ server->config.port,
+ server->config.useTls ? "on" : "off");
+ pushMessage(buf);
+
+ } else if (strncmp(str, "/username ", 10) == 0) {
+ server->config.username = &str[10];
+
+ snprintf(buf, sizeof(buf),
+ "Username changed to: %s",
+ server->config.username.c_str());
+ pushMessage(buf);
+
+ } else if (strncmp(str, "/realname ", 10) == 0) {
+ server->config.realname = &str[10];
+
+ snprintf(buf, sizeof(buf),
+ "Real name changed to: %s",
+ server->config.username.c_str());
+ pushMessage(buf);
+
+ } else if (strncmp(str, "/password", 9) == 0) {
+
+ if (strlen(str) == 9)
+ server->config.password = "";
+ else
+ server->config.password = &str[10];
+
+ if (server->config.password.size() > 0)
+ pushMessage("Server password changed.");
+ else
+ pushMessage("Server password cleared.");
}
} else {
server->sendLine(str);
@@ -697,12 +788,7 @@ void Query::handleCtcp(const char *type, const char *params) {
}
void Query::renamePartner(const char *_partner) {
- Buffer packet;
- packet.writeU32(id);
- packet.writeStr(_partner);
-
- server->bouncer->sendToClients(
- Packet::B2C_WINDOW_RENAME, packet);
-
partner = _partner;
+
+ notifyWindowRename();
}