Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing the if statements in handleCommand() #34

Open
Shu-AFK opened this issue Feb 22, 2024 · 32 comments
Open

Removing the if statements in handleCommand() #34

Shu-AFK opened this issue Feb 22, 2024 · 32 comments
Labels
C/C++ enhancement New feature or request good first issue Good for newcomers

Comments

@Shu-AFK
Copy link
Owner

Shu-AFK commented Feb 22, 2024

This can be done using this approach
image

@Shu-AFK Shu-AFK added enhancement New feature or request C/C++ good first issue Good for newcomers labels Feb 22, 2024
@hvostov
Copy link
Contributor

hvostov commented Apr 16, 2024

Hello, i tryed to run your program, but it doesn't have start script in this path (....\Server\src\scripts\run_exec.bat). Could you add it?

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 16, 2024

According to the current configuration, the run_exec.bat script should be generated automatically upon running the Server.exe file by the create_start_script() function inside Server::setupPort().

This function is attempting to create the run_exec.bat file at the specified absolute path.

The create_start_script() function also logs an error message "Failed to create start script" into a log object if it fails to create the script for some reason. Can you please check any logs or console outputs for this specific error message? Any error message you can provide will be very helpful in troubleshooting this further.

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

Forget to say, the build.bat script couldn't create Server.exe, it was a problem with sqlite3.dll. May be i do smth wrong, but the sqlite3.dll is downloaded from official site and put in the root.

In command line i get this error "C:\Users\ahvostov\sqlite-dll-win-x64-3450300\sqlite3.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x370 [C:\Users\ahvostov\Datatransmission\build\Server\Server.vcxproj]".

Then i tried to do it with sqlite3.lib file and Server.exe was created, but "Failed to create start script". So problem apparantly that I shouldn't build with .lib file.

When i change the CMakeLists.txt of Server like this:
set(SQLITE_LIBRARIES "${SQLITE_PATH}\sqlite3.dll") ---> set(SQLITE_LIBRARIES "${SQLITE_PATH}/sqlite3.lib")
it builds without error, creates Server.exe, but fails to to create start script.

log.txt:
Checking if db is empty..
initialising db..
Table create successfully!
db initialisation successfully
Adding user root..
Adding user was successful
Failed to create start script

Shouldn't it be a "run_exec.bat" in Server\src\scripts\run_exec.bat?

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

Hmm, with the lib file it should work fine, you could try to comment this in Server::setupPort()

if(create_start_script(cwd.string(), port) != 0) {
        log << "Failed to create start script" << std::endl;
        return false;
    }

and create your own run_exec.bat file like this for now

start "" "[Absolute path to Server.exe]\Server.exe" "-p [Port]"

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

Now it just don't logs "Failed to create start script". In console "The system cannot find the path specified." and program hangs.

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

Could you show me the .bat file you created and with what command line args you're running the program with? It's kinda hard for me to debug it without having the same issue, it might be a good idea to step through the program wiht a debugger

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

.bat :
@echo off
start "" "\c\Users\ahvostov\Datatransmission\build\Server\Release\Server.exe" "-p 27015"

./Server.exe -p 27015 -n ahvostov password --set-startup

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

The path should be "C:\Users\ahvostov\Datatransmission\build\Server\Release\Server.exe" instead of "\c\Users\ahvostov\Datatransmission\build\Server\Release\Server.exe"

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

nothing changed... thx for your response, i'll keep trying myself, perhabs i'm too newbie for now

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

Does it still say that it cant find the path?

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

Yes, the same msg "The system cannot find the path specified."

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

Have you tried to go to the executable in file explorer and copy the absolute path from there?

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

Yes, this is exactly that path

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

try to run the program without --set-startup

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

without this it said :
C:/Users/ahvostov/Datatransmission/build/Server/Release/Server.exe: error while loading shared libraries: lz4.dll: cannot open shared object file: No such file or directory

I put it near the Server.exe, and again :
"The system cannot find the path specified."

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

Did you install lz4 using vcpkg?

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

yes

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

I'll try to do everything from beginning at home in the evening and give you feedback.

So, was i right, that it must be a sqlite3.lib instead of .dll in CMakeLists?

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

Since I didn't get a .lib file i used the .dll to link with and it works fine on my machine, but typically it should be a .lib file yeah

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

Have you added the vcpkg bin directory to your path? then you don't have to put it in the same directory and maybe it works then, I'm not really sure why it can't find the dll otherwise

@hvostov
Copy link
Contributor

hvostov commented Apr 17, 2024

the same problem...

$ ./build.bat "C:\Users\ZBook\vcpkg\installed\x64-windows\bin" "C:\Users\ZBook\vcpkg"

sqlite3.dll, lz4.dll placed in bin folder.

Got error: C:\Users\ZBook\vcpkg\installed\x64-windows\bin\sqlite3.dll : fatal error LNK1107: invalid or corrupt file: cannot read at
0x308 [C:\Users\ZBook\Datatransmission\build\Server\Server.vcxproj]

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 17, 2024

This is really weird, I'll check tomorrow when I have time. I'm not really sure why that is though

@hvostov
Copy link
Contributor

hvostov commented Apr 18, 2024

Instead of setting the direct path, i wrote this in CMakeLists:

find_package (SQLite3)
include_directories(${SQLite3_INCLUDE_DIRS})
target_link_libraries (Server ${SQLite3_LIBRARIES})

With this it builds succesfully. Than i dealed with automatically creating of run_exec.bat, by changing helper.cpp:
std::ofstream run_script(R"(..\..\..\Server\src\scripts\run_exec.bat)");
instead of
std::ofstream run_script(R"(..\..\Server\src\scripts\run_exec.bat)");
And

std::string OpenScript = std::format(R"(..\..\..\Server\src\scripts\OpenFirewallPort.bat {})", port);
std::string CheckIfOpenScript = std::format(R"(..\..\..\Server\src\scripts\CheckIfOpen.bat {})", port);

instead of

std::string OpenScript = std::format(R"(..\..\Server\src\scripts\OpenFirewallPort.bat {})", port);
std::string CheckIfOpenScript = std::format(R"(..\..\Server\src\scripts\CheckIfOpen.bat {})", port);

Now it just wrights "Ok." in command line. Is it a right behavior?

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 18, 2024

Yeah, that's the right behaviour, the issue was with the different ide build systems. I'm glad it works now.

@hvostov
Copy link
Contributor

hvostov commented Apr 18, 2024

Now client don't see lz4.dll, i put it near him and it works. When i try to connect to server client says "Credentials are invalid" and server stops with msg "The system cannot find the path specified.". The name and password are the same. Did you have this problem?
My commands for server:
./Server.exe -p 27015 -n alexey qwe123 --set-startup
for client:
./Client.exe -s 127.0.0.1 -p 27015 -u alexey -w qwe123

@hvostov
Copy link
Contributor

hvostov commented Apr 18, 2024

Don't know what's up with cmake, but i created new server project in VS with your code and it works without any problems...

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 18, 2024

So everything works fine now?

@hvostov
Copy link
Contributor

hvostov commented Apr 18, 2024 via email

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 18, 2024

Do you have discord? I feel like thats easier

@hvostov
Copy link
Contributor

hvostov commented Apr 18, 2024 via email

@hvostov
Copy link
Contributor

hvostov commented Apr 19, 2024

my nickname ahvostov

@Shu-AFK
Copy link
Owner Author

Shu-AFK commented Apr 19, 2024

I added you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C/C++ enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants