summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-16 23:55:38 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-16 23:55:38 +0000
commit0c68019a9395b228cdfac9d4b85816ec6319bdb8 (patch)
tree98f194650d6fbce60440ad3ece49f37f183308d4
parent6c0ca5518a0c52ef058a3c7a40fd843fc803853b (diff)
downloadmanaserv-0c68019a9395b228cdfac9d4b85816ec6319bdb8.tar.gz
manaserv-0c68019a9395b228cdfac9d4b85816ec6319bdb8.tar.bz2
manaserv-0c68019a9395b228cdfac9d4b85816ec6319bdb8.tar.xz
manaserv-0c68019a9395b228cdfac9d4b85816ec6319bdb8.zip
Added preliminary interfaces for NetSession, NetComputer, ConnectionHandler
and MessageHandler.
-rw-r--r--src/connectionhandler.cpp25
-rw-r--r--src/connectionhandler.h61
-rw-r--r--src/messagehandler.cpp25
-rw-r--r--src/messagehandler.h47
-rw-r--r--src/netcomputer.cpp25
-rw-r--r--src/netcomputer.h67
-rw-r--r--src/netsession.cpp25
-rw-r--r--src/netsession.h73
8 files changed, 348 insertions, 0 deletions
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
new file mode 100644
index 00000000..354ea608
--- /dev/null
+++ b/src/connectionhandler.cpp
@@ -0,0 +1,25 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "connectionhandler.h"
+
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
new file mode 100644
index 00000000..23bc3504
--- /dev/null
+++ b/src/connectionhandler.h
@@ -0,0 +1,61 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_SERVER_CONNECTIONHANDLER_
+
+#include "netcomputer.h"
+#include "packet.h"
+
+/**
+ * This class represents the connection handler interface. The connection
+ * handler will respond to connect/reconnect/disconnect events and handle
+ * incoming messages, passing them on to registered message handlers.
+ */
+class ConnectionHandler
+{
+ public:
+ /**
+ * Called when a computer connects to a network session.
+ */
+ void computerConnected(NetComputer *computer);
+
+ /**
+ * Called when a computer reconnects to a network session.
+ */
+ void computerReconnected(NetComputer *computer);
+
+ /**
+ * Called when a computer disconnects from a network session.
+ *
+ * <b>Note:</b> After returning from this method the NetComputer
+ * reference is no longer guaranteed to be valid.
+ */
+ void computerDisconnected(NetComputer *computer);
+
+ /**
+ * Called when a computer sends a packet to the network session.
+ */
+ void receivePacket(NetComputer *computer, Packet *packet);
+};
+
+#endif
diff --git a/src/messagehandler.cpp b/src/messagehandler.cpp
new file mode 100644
index 00000000..e7b548a1
--- /dev/null
+++ b/src/messagehandler.cpp
@@ -0,0 +1,25 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "messagehandler.h"
+
diff --git a/src/messagehandler.h b/src/messagehandler.h
new file mode 100644
index 00000000..05bee96b
--- /dev/null
+++ b/src/messagehandler.h
@@ -0,0 +1,47 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_SERVER_MESSAGEHANDLER_
+
+/**
+ * This class represents the message handler interface. This interface is
+ * implemented by classes that mean to handle a certain subset of the incoming
+ * messages, after instanciation they will have to register at a connection
+ * handler before they will receive messages.
+ */
+class MessageHandler
+{
+ public:
+ /**
+ * Called when a message is received with a message ID that corresponds
+ * to an ID this message handler registered to handle.
+ *
+ * Note: A MessageIn is used here which hasn't been defined yet, but
+ * I imagine that Packet instances would be very simple, and wrapped
+ * by both a MessageIn and a MessageOut class that would implement
+ * methods to convenient parse and build packets transparently.
+ */
+ void receiveMessage(Computer *computer, MessageIn *message);
+};
+
+#endif
diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp
new file mode 100644
index 00000000..89317dc0
--- /dev/null
+++ b/src/netcomputer.cpp
@@ -0,0 +1,25 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "netcomputer.h"
+
diff --git a/src/netcomputer.h b/src/netcomputer.h
new file mode 100644
index 00000000..7ac2f833
--- /dev/null
+++ b/src/netcomputer.h
@@ -0,0 +1,67 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_SERVER_NETCOMPUTER_
+
+// Forward declaration
+class NetSession;
+
+/**
+ * This class represents a known computer on the network. For example a
+ * connected client or a server we're connected to.
+ */
+class NetComputer
+{
+ public:
+ /**
+ * Constructor.
+ */
+ NetComputer(NetSession *session);
+
+ /**
+ * Returns the netsession that the computer is attached to.
+ */
+ NetSession *getSession();
+
+ /**
+ * Returns <code>true</code> if this computer is disconnected.
+ */
+ bool isDisconnected();
+
+ /**
+ * Disconnects the computer from the server.
+ */
+ void disconnect(const std::string &reason);
+
+ /**
+ * Sends a packet to this computer.
+ *
+ * Note: When we'd want to allow communication through UDP, we could
+ * introduce the reliable argument, which would could a UDP message
+ * to be sent when set to false.
+ */
+ void send(Packet *p);
+ //void send(Packet *p, bool reliable = true);
+};
+
+#endif
diff --git a/src/netsession.cpp b/src/netsession.cpp
new file mode 100644
index 00000000..1c60990e
--- /dev/null
+++ b/src/netsession.cpp
@@ -0,0 +1,25 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "netsession.h"
+
diff --git a/src/netsession.h b/src/netsession.h
new file mode 100644
index 00000000..e6097db2
--- /dev/null
+++ b/src/netsession.h
@@ -0,0 +1,73 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_SERVER_NETSESSION_
+
+#include "netcomputer.h"
+#include "connectionhandler.h"
+
+/**
+ * This class represents a network session. It implements listening for
+ * connections from and connecting to other computers.
+ */
+class NetSession
+{
+ public:
+ /**
+ * Constructor.
+ */
+ NetSession();
+
+ /**
+ * Destructor.
+ */
+ ~NetSession();
+
+ /**
+ * Start listening for connections and notify the given connection
+ * handler about events.
+ */
+ void startListen(ConnectionHandler *handler, int port);
+
+ /**
+ * Stop listening for connections and disconnect any connected clients.
+ */
+ void stopListen(int port);
+
+ /**
+ * Connect to another network session.
+ */
+ NetComputer *connect(const std::string &ip, int port);
+
+ private:
+ // This class probably needs to keep information about:
+ //
+ // - The list of ports we're listening to and their associated
+ // connection handlers.
+ // - The list of clients that connected and their associated net
+ // computers.
+ // - The list of servers we connected to and their associated net
+ // computers.
+};
+
+#endif