Skip to content

Instantly share code, notes, and snippets.

@JAChapmanII
Last active July 2, 2017 12:25
Show Gist options
  • Save JAChapmanII/c4beeb9ec21a0960ed681d61c3c99a70 to your computer and use it in GitHub Desktop.
Save JAChapmanII/c4beeb9ec21a0960ed681d61c3c99a70 to your computer and use it in GitHub Desktop.
chatServer.cpp - indigo chat server
#include <iostream>
#include <string>
using namespace std;
#include <oil/util.hpp>
#include <oil/db/pgsql.hpp>
#include <indigo/server.hpp>
#include <indigo/client.hpp>
#include <indigo/protoserver.hpp>
using util::word;
using Client = indigo::SecureClient;
using Server = indigo::SecureServer<Client>;
pgsql::ConnectionParameters cp{"test", "jac", ""};
pgsql::Database db{cp.toString()};
struct ChatServer : public indigo::ProtoServer<ChatServer, Client, Server> {
ChatServer();
indigo::ClientCommand<word, word, string> g_message{
"message", {"channel", "nick", "message"}};
};
namespace chat {
void message(ChatServer &server, Client &client, word where, string message) {
cerr << "got message, client nick is " << client.nick() << endl;
server.broadcast(server.g_message(where, client.nick(), message));
}
}
ChatServer::ChatServer() : ProtoServer{db} {
// client -> server commands
bind("message", {"where", "message"}, chat::message, true);
// server -> client commands
bind("message", g_message);
}
int main(int argc, char **argv) {
std::cerr << "indigo chat server" << std::endl;
return indigo::main<ChatServer, Client>(argc, argv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment