wrapping up for a public release

This commit is contained in:
fusion32 2025-08-15 14:59:56 -03:00
parent baaeac349d
commit 783578d28e
9 changed files with 70 additions and 9 deletions

24
LICENSE.txt Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org/>

View File

@ -3,12 +3,12 @@ BUILDDIR = build
OUTPUTEXE = login OUTPUTEXE = login
CXX = g++ CXX = g++
CXXFLAGS = -m64 -fno-strict-aliasing -pedantic -Wno-unused-parameter -Wall -Wextra -pthread --std=c++11 CXXFLAGS = -m64 -fno-strict-aliasing -pedantic -Wno-deprecated-declarations -Wno-unused-parameter -Wall -Wextra -pthread --std=c++11
LFLAGS = -Wl,-t -lcrypto LFLAGS = -Wl,-t -lcrypto
DEBUG ?= 0 DEBUG ?= 0
ifneq ($(DEBUG), 0) ifneq ($(DEBUG), 0)
CXXFLAGS += -g -O0 CXXFLAGS += -g -Og
else else
CXXFLAGS += -O2 CXXFLAGS += -O2
endif endif

13
README.md Normal file
View File

@ -0,0 +1,13 @@
# Tibia 7.7 Login Server
This is a simple login server designed to support [Tibia Game Server](https://github.com/fusion32/tibia-game).
## Compiling
Even though there are no Linux specific features being used, it will currently only compile on Linux. It should be simple enough to support compiling on Windows but I don't think it would add any value, considering the querymanager will be running on Linux and that they need to be both on the same machine. The makefile is very simple and should work as long as OpenSSL's libcrypto, which is the only dependency, is installed. You can add the `-j N` switch to make it compile across N processes.
```
make # build in release mode
make DEBUG=1 # build in debug mode
make clean # remove `build` directory
```
## Running
Similar to the game server, the login server won't boot up if it's not able to connect to the [Query Manager](https://github.com/fusion32/tibia-querymanager). That said, running it is straighforward, requiring only the RSA private key `tibia.pem` and `config.cfg` files to be in the working directory. It is always recommended that the server is setup as a service. There is a *systemd* configuration file (`tibia-login.service`) in the repository that may be used for that purpose. The process is very similar to the one described in the [Game Server](https://github.com/fusion32/tibia-game) so I won't repeat myself here.

View File

@ -4,5 +4,5 @@ LoginPort = 7171
MaxConnections = 10 MaxConnections = 10
LoginTimeout = 10s LoginTimeout = 10s
QueryManagerHost = "127.0.0.1" QueryManagerHost = "127.0.0.1"
QueryManagerPort = 7174 QueryManagerPort = 7173
QueryManagerPassword = "a6glaf0c" QueryManagerPassword = "a6glaf0c"

View File

@ -13,6 +13,7 @@ void LogAdd(const char *Prefix, const char *Format, ...){
LocalTime.tm_year + 1900, LocalTime.tm_mon + 1, LocalTime.tm_mday, LocalTime.tm_year + 1900, LocalTime.tm_mon + 1, LocalTime.tm_mday,
LocalTime.tm_hour, LocalTime.tm_min, LocalTime.tm_sec, LocalTime.tm_hour, LocalTime.tm_min, LocalTime.tm_sec,
Prefix, Entry); Prefix, Entry);
fflush(stdout);
} }
} }
@ -32,6 +33,7 @@ void LogAddVerbose(const char *Prefix, const char *Function,
LocalTime.tm_year + 1900, LocalTime.tm_mon + 1, LocalTime.tm_mday, LocalTime.tm_year + 1900, LocalTime.tm_mon + 1, LocalTime.tm_mday,
LocalTime.tm_hour, LocalTime.tm_min, LocalTime.tm_sec, LocalTime.tm_hour, LocalTime.tm_min, LocalTime.tm_sec,
Prefix, Function, Entry); Prefix, Function, Entry);
fflush(stdout);
} }
} }

View File

@ -265,8 +265,8 @@ void ProcessConnections(void){
} }
if(AssignConnection(Socket, Addr, Port) == NULL){ if(AssignConnection(Socket, Addr, Port) == NULL){
LOG_ERR("Rejecting connection from %08X due to max number of" LOG_ERR("Rejecting connection from %08X:%d due to max number of"
" connections being reached (%d)", Addr, g_MaxConnections); " connections being reached (%d)", Addr, Port, g_MaxConnections);
close(Socket); close(Socket);
} }
} }

View File

@ -290,7 +290,7 @@ struct TWriteBuffer{
} }
void Rewrite16(int Position, uint16 Value){ void Rewrite16(int Position, uint16 Value){
if((Position + 2) <= this->Position){ if((Position + 2) <= this->Position && !this->Overflowed()){
BufferWrite16LE(this->Buffer + Position, Value); BufferWrite16LE(this->Buffer + Position, Value);
} }
} }

View File

@ -147,7 +147,7 @@ int ExecuteQuery(TQueryManagerConnection *Connection, bool AutoReconnect,
} }
const int MaxAttempts = 2; const int MaxAttempts = 2;
for(int Attempts = 0; true; Attempts += 1){ for(int Attempt = 1; true; Attempt += 1){
int WriteSize = WriteBuffer->Position; int WriteSize = WriteBuffer->Position;
if(!IsConnected(Connection)){ if(!IsConnected(Connection)){
if(!AutoReconnect){ if(!AutoReconnect){
@ -173,7 +173,7 @@ int ExecuteQuery(TQueryManagerConnection *Connection, bool AutoReconnect,
if(!WriteExact(Connection->Socket, Connection->Buffer, WriteSize)){ if(!WriteExact(Connection->Socket, Connection->Buffer, WriteSize)){
Disconnect(Connection); Disconnect(Connection);
if(Attempts >= MaxAttempts){ if(Attempt >= MaxAttempts){
LOG_ERR("Failed to write request"); LOG_ERR("Failed to write request");
return QUERY_STATUS_FAILED; return QUERY_STATUS_FAILED;
} }
@ -183,7 +183,7 @@ int ExecuteQuery(TQueryManagerConnection *Connection, bool AutoReconnect,
uint8 Help[4]; uint8 Help[4];
if(!ReadExact(Connection->Socket, Help, 2)){ if(!ReadExact(Connection->Socket, Help, 2)){
Disconnect(Connection); Disconnect(Connection);
if(Attempts >= MaxAttempts){ if(Attempt >= MaxAttempts){
LOG_ERR("Failed to read response size"); LOG_ERR("Failed to read response size");
return QUERY_STATUS_FAILED; return QUERY_STATUS_FAILED;
} }

22
tibia-login.service Normal file
View File

@ -0,0 +1,22 @@
# Basic SYSTEMD service file for the Tibia Login Server
[Unit]
Description=Tibia Login Server
After=network.target
Requires=tibia-querymanager.service
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
User=tibia-login
Group=tibia-login
ExecStart=/opt/tibia/login/login
WorkingDirectory=/opt/tibia/login/
Restart=always
RestartSec=10
LimitCORE=infinity
StandardOutput=journal
StandardError=journal
SyslogIdentifier=%n