dogu-team / gamium

Multiple game engine sdk for scripting the behavior of game users
https://dogu-team.github.io/gamium/
MIT License
94 stars 6 forks source link

[Bug]: Strings over RPC fail to be parsed #13

Closed N3X15 closed 5 months ago

N3X15 commented 6 months ago

Steps to reproduce

// Note: This file doesn't actually need to exist.
namespace Your.RPC
{
    public static class Class
        /// <summary>
        /// Test method
        /// </summary>
        /// <param name="aString"></param>
        [Preserve]
        public static void AMethodThatAcceptsASingleString(string aString)
        {
            // Will never make it here.
            AssertIsDevBuild();
            Debug.Log("SUCCESS");
        }
    }
}
from gamium import *

service = TcpGamiumService("127.0.0.1", 50061)
gamium = GamiumClient(service)

gamium.connect()

# Send any non-numeric string over RPC
gamium.execute_rpc(
    RpcBy.method(
        "Your.RPC.Class",
        "AMethodThatAcceptsASingleString",
        "c11557d5-ffcc-47fc-9263-2b1717eb070d",
    )
)

Expected result

Client successfully sends the request and prints out SUCCESS in console.

Actual result

Client crashes prior to sending request to server.

$ python test.py
INFO: GamiumClient.connect
INFO: Connecting to 127.0.0.1:50061
INFO: GamiumClient.execute_rpc By: 0, class: Your.RPC.Class, target: AMethodThatAcceptsASingleString
Traceback (most recent call last):
  File "F:\ABI\cvr_unit_tests\test.py", line 7, in <module>
    gamium.execute_rpc(
  File "C:\Users\N3X15\AppData\Local\pypoetry\Cache\virtualenvs\cvr-unit-tests-K3olf5zB-py3.11\Lib\site-packages\gamium\gamium_client.py", line 135, in execute_rpc
    res = self._service.request(create_execute_rpc(locator.by, locator.class_name, locator.target_name, params))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\N3X15\AppData\Local\pypoetry\Cache\virtualenvs\cvr-unit-tests-K3olf5zB-py3.11\Lib\site-packages\gamium\tcp_gamium_service.py", line 104, in request
    raise e
  File "C:\Users\N3X15\AppData\Local\pypoetry\Cache\virtualenvs\cvr-unit-tests-K3olf5zB-py3.11\Lib\site-packages\gamium\tcp_gamium_service.py", line 98, in request
    return self.pop_message(req)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\N3X15\AppData\Local\pypoetry\Cache\virtualenvs\cvr-unit-tests-K3olf5zB-py3.11\Lib\site-packages\gamium\tcp_gamium_service.py", line 126, in pop_message
    raise GamiumError(response.error.code, f"request response error: {reason}")
gamium.errors.gamium_error.GamiumError: (301, "request response error: Unexpected character encountered while parsing value: c. Path '', line 0, position 0.")

Version

2.0.9

N3X15 commented 6 months ago

Use-case: Our testing process requires that we send GUIDs over RPC for loading worlds, since actually browsing for the world in UI is currently an overly-complicated task for automation.

WORKAROUND: Sending a Dict[str, Any] seems to work fine:

# Send any GUID over RPC
gamium.execute_rpc(
    RpcBy.method(
        "Your.RPC.Class",
        "AMethodThatAcceptsAJSONObject",
        {"guid": "c11557d5-ffcc-47fc-9263-2b1717eb070d"},
    )
)

You will, however, need to change your method signature:

        /// <summary>
        /// Test method
        /// </summary>
        [Preserve]
        public static void AMethodThatAcceptsAJSONObject(JObject json)
        {
            var guid = (string)json["guid"];
            Debug.Log("AMethodThatAcceptsAJSONObject: "+guid);
        }
yowpark commented 6 months ago

The problematic code has been fixed, but deploy will be delayed due to PyPI account issues.

yowpark commented 5 months ago

Fixed in version 2.0.10.