summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--src/accounthandler.cpp11
-rw-r--r--src/client.cpp46
-rw-r--r--src/connectionhandler.cpp7
-rw-r--r--src/connectionhandler.h5
-rw-r--r--src/defines.h35
6 files changed, 87 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 53570aea..9af72fbb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
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
+ behaviour in protocol. Some cleanups.
* src/client.cpp, src/storage.h, src/dalstorage.cpp, src/dalstorage.h,
src/main.cpp, src/defines.h, src/accounthandler.cpp, src/Makefile.am:
Implemented server response handling to the test client. Fixed a bug
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 3aabb9bb..7632fdcc 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -22,6 +22,7 @@
*/
#include "accounthandler.h"
+#include "connectionhandler.h"
#include "debug.h"
#include "storage.h"
#include "account.h"
@@ -69,7 +70,15 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
LOG_INFO("Already logged in as " << computer.getAccount()->getName()
<< ".", 1)
LOG_INFO("Please logout first.", 1)
- result.writeShort(LOGIN_ALREADY_LOGGED);
+ result.writeByte(LOGIN_ALREADY_LOGGED);
+ break;
+ }
+ if (connectionHandler->getClientNumber() >= MAX_CLIENTS )
+ {
+ // Too much clients logged in.
+ LOG_INFO("Client couldn't log. Already has " << MAX_CLIENTS
+ << " logged in.", 1)
+ result.writeByte(LOGIN_SERVER_FULL);
break;
}
diff --git a/src/client.cpp b/src/client.cpp
index 713e429a..c9213964 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1,6 +1,5 @@
#include <SDL.h>
#include <SDL_net.h>
-#include <stdlib.h>
#include <iostream>
#include "defines.h"
#include "messageout.h"
@@ -274,6 +273,10 @@ int main(int argc, char *argv[])
case REGISTER_EXISTS_EMAIL:
std::cout << "Account registering: Email already exists." << std::endl;
break;
+ default:
+ case REGISTER_UNKNOWN:
+ std::cout << "Account registering: Unknown error." << std::endl;
+ break;
}
break;
@@ -293,6 +296,10 @@ int main(int argc, char *argv[])
case UNREGISTER_INVALID_UNSUFFICIENT_RIGHTS:
std::cout << "Account unregistering: unsufficient rights." << std::endl;
break;
+ default:
+ case UNREGISTER_UNKNOWN:
+ std::cout << "Account unregistering: Unknown error." << std::endl;
+ break;
}
break;
@@ -324,7 +331,7 @@ int main(int argc, char *argv[])
std::cout << "Login: Already logged with another account." << std::endl;
break;
case LOGIN_SERVER_FULL:
- std::cout << "TODO:Login: Server has reached maximum of clients." << std::endl;
+ std::cout << "Login: Server has reached maximum of clients." << std::endl;
break;
case LOGIN_ACCOUNT_BANNED:
std::cout << "Login: Your account has been banned." << std::endl;
@@ -361,7 +368,6 @@ int main(int argc, char *argv[])
case PASSCHG_OK:
std::cout << "Password correctly changed." << std::endl;
break;
- default:
case PASSCHG_NOLOGIN:
std::cout << "Password change: Not logged in." << std::endl;
break;
@@ -371,6 +377,10 @@ int main(int argc, char *argv[])
case PASSCHG_INVALID:
std::cout << "Password change: New password is invalid." << std::endl;
break;
+ default:
+ case PASSCHG_UNKNOWN:
+ std::cout << "Password change: Unknown error." << std::endl;
+ break;
}
}
break;
@@ -382,7 +392,6 @@ int main(int argc, char *argv[])
case EMAILCHG_OK:
std::cout << "Email correctly changed." << std::endl;
break;
- default:
case EMAILCHG_NOLOGIN:
std::cout << "Email change: Not logged in." << std::endl;
break;
@@ -392,6 +401,10 @@ int main(int argc, char *argv[])
case EMAILCHG_INVALID:
std::cout << "Email change: New Email is invalid." << std::endl;
break;
+ default:
+ case EMAILCHG_UNKNOWN:
+ std::cout << "Email change: Unknown error." << std::endl;
+ break;
}
}
break;
@@ -403,9 +416,12 @@ int main(int argc, char *argv[])
case EMAILGET_OK:
std::cout << "Current Email: " << msg.readString() << std::endl;
break;
- default:
case EMAILGET_NOLOGIN:
- std::cout << "Email change: Not logged in." << std::endl;
+ std::cout << "Get Email: Not logged in." << std::endl;
+ break;
+ default:
+ case EMAILGET_UNKNOWN:
+ std::cout << "Get Email: Unknown error." << std::endl;
break;
}
}
@@ -440,6 +456,10 @@ int main(int argc, char *argv[])
case CREATE_INVALID_RAW_STATS:
std::cout << "TODO: Character Creation: Invalid Raw Stats." << std::endl;
break;
+ default:
+ case CREATE_UNKNOWN:
+ std::cout << "Character Creation: Unknown error." << std::endl;
+ break;
}
}
break;
@@ -459,7 +479,11 @@ int main(int argc, char *argv[])
std::cout << "Character Deletion: Not logged in." << std::endl;
break;
case DELETE_NO_MORE_CHARACTERS:
- std::cout << "Character Creation: No more characters." << std::endl;
+ std::cout << "Character Deletion: No more characters." << std::endl;
+ break;
+ default:
+ case DELETE_UNKNOWN:
+ std::cout << "Character Deletion: Unknown error." << std::endl;
break;
}
}
@@ -482,6 +506,10 @@ int main(int argc, char *argv[])
case SELECT_NOT_YET_CHARACTERS:
std::cout << "Character Selection: No character to select." << std::endl;
break;
+ default:
+ case SELECT_UNKNOWN:
+ std::cout << "Character Selection: Unknown error." << std::endl;
+ break;
}
}
break;
@@ -518,6 +546,10 @@ int main(int argc, char *argv[])
std::cout << "Character List: Not logged in."
<< std::endl;
break;
+ default:
+ case CHAR_LIST_UNKNOWN:
+ std::cout << "Character List: Unknown error." << std::endl;
+ break;
}
}
break;
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
index 3009ae56..9ce663df 100644
--- a/src/connectionhandler.cpp
+++ b/src/connectionhandler.cpp
@@ -33,8 +33,6 @@
#include "script.h"
#endif
-#define MAX_CLIENTS 1024
-
/**
* TEMPORARY
* Split a string into a std::vector delimiting elements by 'split'. This
@@ -295,3 +293,8 @@ void ConnectionHandler::sendAround(tmwserv::BeingPtr beingPtr, MessageOut &msg)
}
}
}
+
+unsigned int ConnectionHandler::getClientNumber()
+{
+ return clients.size();
+}
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
index 54ed6a06..9b0938e1 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -123,6 +123,11 @@ class ConnectionHandler
*/
void sendAround(tmwserv::BeingPtr, MessageOut &);
+ /**
+ * Return the number of connected clients.
+ */
+ unsigned int getClientNumber();
+
private:
std::map<unsigned int, MessageHandler*> handlers;
diff --git a/src/defines.h b/src/defines.h
index 43841ffe..bce3e207 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -55,6 +55,9 @@ typedef enum {
} Genders;
enum {
+ // Network related
+ MAX_CLIENTS = 1024,
+
// Registering related
MIN_LOGIN_LENGTH = 4,
MAX_LOGIN_LENGTH = 16,
@@ -176,7 +179,7 @@ enum {
// Logout return values
enum {
LOGOUT_OK = 0,
- LOGOUT_UNSUCCESSFULL
+ LOGOUT_UNSUCCESSFULL,
};
// Account register return values
@@ -186,7 +189,8 @@ enum {
REGISTER_INVALID_PASSWORD,
REGISTER_INVALID_EMAIL,
REGISTER_EXISTS_USERNAME,
- REGISTER_EXISTS_EMAIL
+ REGISTER_EXISTS_EMAIL,
+ REGISTER_UNKNOWN
};
// Account deletion return values
@@ -194,7 +198,8 @@ enum {
UNREGISTER_OK = 0,
UNREGISTER_INVALID_USERNAME,
UNREGISTER_INVALID_PASSWORD,
- UNREGISTER_INVALID_UNSUFFICIENT_RIGHTS
+ UNREGISTER_INVALID_UNSUFFICIENT_RIGHTS,
+ UNREGISTER_UNKNOWN
};
// Character creation return values
@@ -206,7 +211,8 @@ enum {
CREATE_INVALID_RAW_STATS,
CREATE_EXISTS_NAME,
CREATE_TOO_MUCH_CHARACTERS,
- CREATE_NOLOGIN
+ CREATE_NOLOGIN,
+ CREATE_UNKNOWN
};
// Character deletion return values
@@ -214,7 +220,8 @@ enum {
DELETE_OK = 0,
DELETE_INVALID_NAME,
DELETE_NO_MORE_CHARACTERS,
- DELETE_NOLOGIN
+ DELETE_NOLOGIN,
+ DELETE_UNKNOWN
};
// Character selection return values
@@ -223,13 +230,15 @@ enum {
SELECT_OK = 0,
SELECT_INVALID,
SELECT_NOT_YET_CHARACTERS,
- SELECT_NOLOGIN
+ SELECT_NOLOGIN,
+ SELECT_UNKNOWN
};
// Character's list return values
enum {
CHAR_LIST_OK = 0,
- CHAR_LIST_NOLOGIN
+ CHAR_LIST_NOLOGIN,
+ CHAR_LIST_UNKNOWN
};
// Email change return values
@@ -237,13 +246,15 @@ enum {
EMAILCHG_OK = 0,
EMAILCHG_NOLOGIN,
EMAILCHG_INVALID,
- EMAILCHG_EXISTS_EMAIL
+ EMAILCHG_EXISTS_EMAIL,
+ EMAILCHG_UNKNOWN
};
// Get Email return values
enum {
EMAILGET_OK = 0,
- EMAILGET_NOLOGIN
+ EMAILGET_NOLOGIN,
+ EMAILGET_UNKNOWN
};
// Password change return values
@@ -251,7 +262,8 @@ enum {
PASSCHG_OK = 0,
PASSCHG_NOLOGIN,
PASSCHG_INVALID,
- PASSCHG_MISMATCH
+ PASSCHG_MISMATCH,
+ PASSCHG_UNKNOWN
};
// Chat errors return values
@@ -261,7 +273,8 @@ enum {
CHAT_NO_CHARACTER_SELECTED,
CHAT_USING_BAD_WORDS,
CHATCMD_UNHANDLED_COMMAND,
- CHATCMD_UNSUFFICIENT_RIGHTS
+ CHATCMD_UNSUFFICIENT_RIGHTS,
+ CHATCMD_UNKNOWN
};
// Object type enumeration