Skip to content

sniper00/proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asio based game server proxy template

  1. Forward client message to specific game server, by using a profile node.json
  2. Key exchange and data encryption
  3. Multithread and have simple load balance policy: Least Connections
  4. Auto reload profile node.json every 10 seconds for add new game server.
  5. Protocol convert: Convert other tcp protocol to moon.PTYPE_SOCKET_MOON

Use

  1. If you want convert other tcp protocol, modify this code:
    static awaitable<asio::error_code> read_message(tcp::socket& sock, asio::streambuf& buf)
    {
        std::tuple<asio::error_code, size_t> res =
            co_await asio::async_read(sock, buf, asio::transfer_exactly(sizeof(uint16_t)), use_nothrow_awaitable);
        if (!std::get<0>(res))
        {
            auto data = reinterpret_cast<const char*>(buf.data().data());
            uint16_t size;
            memcpy(&size, data, sizeof(uint16_t));
            size = network_to_host_short(size);
            buf.prepare(size);
            res = co_await asio::async_read(sock, buf, asio::transfer_exactly(size), use_nothrow_awaitable);
        }
        co_return std::get<0>(res);
    }
  1. Write your handeshark code here:
 static awaitable<bool> handshake(tcp::socket& from, tcp::socket& to)
    {
        //asio::streambuf handshake;
        //auto e1 = co_await read_message(from, handshake);
        //if (e1)
        //{
        //    CONSOLE_LOG("Handshake read %s: %s\n", address(from).data(), e1.message().data());
        //    co_return false;
        //}

        // auto content = message_content(handshake);
        // TODO
        // e. Diffie-Hellman Key exchange
    ...
  1. Handle client to server message: transfer_client_to_server
  2. Handle server to client message: transfer_server_to_client

Build

  • windows: premake5 vs2022
  • linux(gcc 11+): premake5 gmake & make config=release

Run

# proxy [-p listenport] [-c filename] [-t threadnum]
./proxy -p 5001 -c node.json -t 32

About

asio based game-server proxy template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published