summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2006-01-05 22:31:06 +0000
committerYohann Ferreira <bertram@cegetel.net>2006-01-05 22:31:06 +0000
commitac150f3543caf86fd071c73f53373b4ea243fa24 (patch)
treefe9153f45c42d07e32fe20b5dfcb8a0baf448273
parent48375c7ea578313a0b578078eadada2e3744b363 (diff)
downloadmanaserv-ac150f3543caf86fd071c73f53373b4ea243fa24.tar.gz
manaserv-ac150f3543caf86fd071c73f53373b4ea243fa24.tar.bz2
manaserv-ac150f3543caf86fd071c73f53373b4ea243fa24.tar.xz
manaserv-ac150f3543caf86fd071c73f53373b4ea243fa24.zip
Added a standard version check.
-rw-r--r--ChangeLog5
-rw-r--r--src/accounthandler.cpp24
-rw-r--r--src/client.cpp46
-rw-r--r--src/defines.h15
-rw-r--r--src/main.cpp4
5 files changed, 87 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 9af72fbb..d3025903 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2005-01-04 Yohann Ferreira <bertram@cegetel.net>
+ * src/defines.h, src/accounthandler.cpp, src/main.cpp, src/client.cpp:
+ Added a standard version check.
+
+2005-01-04 Yohann Ferreira <bertram@cegetel.net>
+
* src/connectionhandler.h, src.connectionhandler.cpp, src/client.cpp,
src/accounthandler.cpp, src/defines.h: Added a check if the maximum
number of client is already logged in at login attempt. Added a default
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 7632fdcc..a8b02a92 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -60,12 +60,24 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
{
case CMSG_LOGIN:
{
+ std::string clientVersion = message.readString();
std::string username = message.readString();
std::string password = message.readString();
LOG_INFO(username << " is trying to login.", 1)
result.writeShort(SMSG_LOGIN_RESPONSE);
+#ifdef PACKAGE_VERSION
+ if (clientVersion <= PACKAGE_VERSION)
+#else
+ if (clientVersion <= DEFAULT_PACKAGE_VERSION)
+#endif
+ {
+ LOG_INFO("Client has an unsufficient version number to login.", 1)
+ result.writeByte(LOGIN_INVALID_VERSION);
+ break;
+ }
+
if (computer.getAccount().get() != NULL) {
LOG_INFO("Already logged in as " << computer.getAccount()->getName()
<< ".", 1)
@@ -153,11 +165,23 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_REGISTER:
{
+ std::string clientVersion = message.readString();
std::string username = message.readString();
std::string password = message.readString();
std::string email = message.readString();
result.writeShort(SMSG_REGISTER_RESPONSE);
+#ifdef PACKAGE_VERSION
+ if (clientVersion <= PACKAGE_VERSION)
+#else
+ if (clientVersion <= DEFAULT_PACKAGE_VERSION)
+#endif
+ {
+ LOG_INFO("Client has an unsufficient version number to login.", 1)
+ result.writeByte(REGISTER_INVALID_VERSION);
+ break;
+ }
+
// Checking if the Name is slang's free.
if (!slangsFilter->filterContent(username))
{
diff --git a/src/client.cpp b/src/client.cpp
index c9213964..f98d45d4 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1,3 +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 <SDL.h>
#include <SDL_net.h>
#include <iostream>
@@ -7,6 +29,16 @@
int main(int argc, char *argv[])
{
+
+#if (defined __USE_UNIX98 || defined __FreeBSD__)
+#include "../config.h"
+#endif
+#ifdef PACKAGE_VERSION
+ std::cout << "The Mana World Test Client v" << PACKAGE_VERSION << std::endl;
+#else
+ std::cout << "The Mana World Test Client v" << DEFAULT_PACKAGE_VERSION << std::endl;
+#endif
+
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
std::cout << "SDL_Init: " << SDL_GetError() << std::endl;
@@ -63,6 +95,12 @@ int main(int argc, char *argv[])
case 1:
// Register
msg.writeShort(CMSG_REGISTER);
+ // We send the client version
+#ifdef PACKAGE_VERSION
+ msg.writeString(PACKAGE_VERSION);
+#else
+ msg.writeString(DEFAULT_PACKAGE_VERSION);
+#endif
std::cout << "Account name: ";
std::cin >> line;
msg.writeString(line);
@@ -88,6 +126,12 @@ int main(int argc, char *argv[])
case 3:
// Login
msg.writeShort(CMSG_LOGIN);
+ // We send the client version
+#ifdef PACKAGE_VERSION
+ msg.writeString(PACKAGE_VERSION);
+#else
+ msg.writeString(DEFAULT_PACKAGE_VERSION);
+#endif
std::cout << "Account name: ";
std::cin >> line;
msg.writeString(line);
@@ -325,7 +369,7 @@ int main(int argc, char *argv[])
std::cout << "Login: Invalid Password." << std::endl;
break;
case LOGIN_INVALID_VERSION:
- std::cout << "TODO:Login: Invalid Version." << std::endl;
+ std::cout << "Login: Invalid Version." << std::endl;
break;
case LOGIN_ALREADY_LOGGED:
std::cout << "Login: Already logged with another account." << std::endl;
diff --git a/src/defines.h b/src/defines.h
index bce3e207..c344011f 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -54,9 +54,13 @@ typedef enum {
GENDER_UNKNOWN
} Genders;
-enum {
+ // That value will be arithmetically compared
+ // using std::string >= operator.
+const std::string CLIENT_MINIMUM_VERSION = "0",
+ DEFAULT_PACKAGE_VERSION = "0";
+
// Network related
- MAX_CLIENTS = 1024,
+const unsigned int MAX_CLIENTS = 1024,
// Registering related
MIN_LOGIN_LENGTH = 4,
@@ -86,8 +90,8 @@ enum {
* Determine the area in which a character
* can hear another one speak
*/
- AROUND_AREA_IN_TILES = 10
-};
+ AROUND_AREA_IN_TILES = 10;
+
/**
* Enumerated type for communicated messages
@@ -179,7 +183,7 @@ enum {
// Logout return values
enum {
LOGOUT_OK = 0,
- LOGOUT_UNSUCCESSFULL,
+ LOGOUT_UNSUCCESSFULL
};
// Account register return values
@@ -188,6 +192,7 @@ enum {
REGISTER_INVALID_USERNAME,
REGISTER_INVALID_PASSWORD,
REGISTER_INVALID_EMAIL,
+ REGISTER_INVALID_VERSION,
REGISTER_EXISTS_USERNAME,
REGISTER_EXISTS_EMAIL,
REGISTER_UNKNOWN
diff --git a/src/main.cpp b/src/main.cpp
index d39b04c5..83b30246 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -343,8 +343,10 @@ void parseOptions(int argc, char *argv[])
*/
int main(int argc, char *argv[])
{
-#if (defined __USE_UNIX98 || defined __FreeBSD__)
+#ifdef PACKAGE_VERSION
LOG_INFO("The Mana World Server v" << PACKAGE_VERSION, 0)
+#else
+ LOG_INFO("The Mana World Server v" << DEFAULT_PACKAGE_VERSION, 0)
#endif
// Parse Command Line Options