1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Fix connections amount problem

This commit is contained in:
nordsoft
2022-11-14 01:48:13 +04:00
parent 694fedc662
commit 915d215076
4 changed files with 16 additions and 14 deletions

View File

@@ -207,7 +207,7 @@ int main(int argc, char * argv[])
("lobby-port", po::value<ui16>(), "port to remote lobby")
("lobby-host", "if this client hosts session")
("lobby-uuid", po::value<std::string>(), "uuid to the server")
("lobby-connections", po::value<std::string>(), "connections of server")
("lobby-connections", po::value<ui16>(), "connections of server")
("uuid", po::value<std::string>(), "uuid for the client");
if(argc > 1)
@@ -503,7 +503,7 @@ int main(int argc, char * argv[])
if(vm.count("lobby-host"))
{
session["host"].Bool() = true;
session["hostConnections"].String() = vm["lobby-connections"].as<std::string>();
session["hostConnections"].String() = std::to_string(vm["lobby-connections"].as<ui16>());
session["hostUuid"].String() = vm["lobby-uuid"].as<std::string>();
logGlobal->info("This client will host session, server uuid is %s", session["hostUuid"].String());
}

View File

@@ -861,6 +861,7 @@ void CServerHandler::threadRunServer()
comm += " --enable-shm-uuid";
}
comm += " > \"" + logName + '\"';
logGlobal->info("Server command line: %s", comm);
#ifdef VCMI_WINDOWS
int result = -1;

View File

@@ -14,7 +14,7 @@ SERVER_PORT = 5002 # port we want to use
#logging
logHandlerHighlevel = logging.FileHandler('proxyServer.log')
logHandlerHighlevel.setLevel(logging.WARNING)
logHandlerHighlevel.setLevel(logging.INFO)
logHandlerLowlevel = logging.FileHandler('proxyServer_debug.log')
logHandlerLowlevel.setLevel(logging.DEBUG)
@@ -308,6 +308,7 @@ def startRoom(room: Room):
logging.warning(f"[*] Starting session {session.name}")
session.host_uuid = str(uuid.uuid4())
hostMessage = f":>>HOST:{session.host_uuid}:{room.joined - 1}" #one client will be connected locally
logging.debug(f" host: {session.host_uuid} connections {room.joined - 1}")
#host message must be before start message
send(room.host, hostMessage)
@@ -334,14 +335,14 @@ def dispatch(cs: socket, sender: Sender, arr: bytes):
msg = str(arr)
if msg.find("Aiya!") != -1:
sender.client = ClientPipe()
logging.debug(" vcmi recognized")
logging.debug(" vcmi recognized")
if sender.isPipe():
if sender.client.auth: #if already playing - sending raw bytes as is
sender.client.prevmessages.append(arr)
else:
sender.client.prevmessages.append(struct.pack('<I', len(arr)) + arr) #pack message
logging.debug(" packing message")
logging.debug(" packing message")
#search fo application type in the message
match = re.search(r"\((\w+)\)", msg)
_appType = ''
@@ -351,13 +352,13 @@ def dispatch(cs: socket, sender: Sender, arr: bytes):
#extract uuid from message
_uuid = arr.decode()
logging.debug(f" decoding {_uuid}")
logging.debug(f" decoding {_uuid}")
if not _uuid == '' and not sender.client.apptype == '':
#search for uuid
for session in sessions:
#verify uuid of connected application
if _uuid.find(session.host_uuid) != -1 and sender.client.apptype == "server":
logging.debug(f" apptype {sender.client.apptype} uuid {_uuid}")
logging.info(f" apptype {sender.client.apptype} uuid {_uuid}")
session.addConnection(cs, True)
sender.client.session = session
sender.client.auth = True
@@ -365,13 +366,13 @@ def dispatch(cs: socket, sender: Sender, arr: bytes):
# this is workaround to send only one remaining byte
# WARNING: reversed byte order is not supported
sender.client.prevmessages.append(cs.recv(1))
logging.debug(f" binding server connection to session {session.name}")
logging.info(f" binding server connection to session {session.name}")
break
if sender.client.apptype == "client":
for p in session.clients_uuid:
if _uuid.find(p) != -1:
logging.debug(f" apptype {sender.client.apptype} uuid {_uuid}")
logging.info(f" apptype {sender.client.apptype} uuid {_uuid}")
#client connection
session.addConnection(cs, False)
sender.client.session = session
@@ -380,7 +381,7 @@ def dispatch(cs: socket, sender: Sender, arr: bytes):
# this is workaround to send only one remaining byte
# WARNING: reversed byte order is not supported
sender.client.prevmessages.append(cs.recv(1))
logging.debug(f" binding client connection to session {session.name}")
logging.info(f" binding client connection to session {session.name}")
break
#game mode

View File

@@ -202,12 +202,12 @@ void CVCMIServer::run()
void CVCMIServer::establishRemoteConnections()
{
uuid = cmdLineOptions["lobby-uuid"].as<std::string>();
int numOfConnections = cmdLineOptions["connections"].as<ui8>();
int numOfConnections = cmdLineOptions["connections"].as<ui16>();
auto address = cmdLineOptions["lobby"].as<std::string>();
int port = cmdLineOptions["lobby-port"].as<ui16>();
logGlobal->info("Server is connecting to remote at %s:%d with uuid %d times", address, port, uuid, numOfConnections);
logGlobal->info("Server is connecting to remote at %s:%d with uuid %s %d times", address, port, uuid, numOfConnections);
for(int i = 0; i < numOfConnections && i == remotePipeConnections; ++i, ++remotePipeConnections)
for(int i = 0; i < numOfConnections; ++i)
connectToRemote(address, port);
}
@@ -1000,7 +1000,7 @@ static void handleCommandOptions(int argc, char * argv[], boost::program_options
("lobby", po::value<std::string>(), "address to remote lobby")
("lobby-port", po::value<ui16>(), "port at which server connect to remote lobby")
("lobby-uuid", po::value<std::string>(), "")
("connections", po::value<ui8>(), "amount of connections to remote lobby");
("connections", po::value<ui16>(), "amount of connections to remote lobby");
if(argc > 1)
{