Skip to content

Commit

Permalink
new rep
Browse files Browse the repository at this point in the history
  • Loading branch information
ucat committed Jan 20, 2024
1 parent 929278f commit 43dab4b
Show file tree
Hide file tree
Showing 776 changed files with 244,711 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# will have compiled files and executables
debug/
target/
node_modules/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand All @@ -12,3 +13,10 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

*.pyc

*.log
*.log.*

dump.rdb
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "external/behavior3"]
path = external/behavior3
url = [email protected]:behavior3/behavior3py.git
[submodule "tools/behavior3editor"]
path = tools/behavior3editor
url = [email protected]:behavior3/behavior3editor.git
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rust-analyzer.linkedProjects": [
".\\client\\Cargo.toml",
".\\server\\Cargo.toml"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# geese
# geese
23 changes: 23 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "geese_client"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.12.0"
thrift = "0.17.0"
serde = "1.0.163"
serde_json = "1.0.96"
tracing = "0.1.37"
uuid = "1.3.3"
consulrs = "0.1.0"
tokio = { version = "1.28.2", features = ["full"] }
pyo3 = { version = "0.20.0", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20.0", features = ["attributes", "tokio-runtime"] }
client = { path = "../crates/client", version = "0.1.0" }

[lib]
name="pyclient"
crate-type = ["cdylib"]
8 changes: 8 additions & 0 deletions client/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# __init__.py

from .app import *
from .session import *
from .player import *
from .subentity import *
from .receiver import *
from .msgpack import *
127 changes: 127 additions & 0 deletions client/engine/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding: UTF-8 -*-
from __future__ import annotations
import time

from collections.abc import Callable

from .pyclient import ClientPump
from .context import context
from .conn_msg_handle import conn_msg_handle
from .player import *
from .subentity import *
from .receiver import *

class client_event_handle(ABC):
@abstractmethod
def on_kick_off(self, prompt_info:str):
pass

@abstractmethod
def on_transfer_complete(self):
pass

def singleton(cls):
_instance = {}

def inner():
if cls not in _instance:
_instance[cls] = cls()
return _instance[cls]
return inner

@singleton
class app(object):
def __init__(self):
self.ctx:context = None

self.__is_run__ = True
self.__conn_handle__:conn_msg_handle = None
self.__entity_create_method__:dict[str, Callable[[str, dict]]] = {}
self.__pump__ = None

self.player_mgr:player_manager = None
self.subentity_mgr:subentity_manager = None
self.receiver_mgr:receiver_manager = None

self.__hub_global_callback__:dict[str, Callable[[str, bytes]]] = {}

self.client_event_handle = None

def build(self, handle:client_event_handle):
self.ctx = context()
self.client_event_handle = handle
self.__conn_handle__ = conn_msg_handle()
self.__pump__ = ClientPump(self.ctx.ctx)
return self

def on_kick_off(self, prompt_info:str):
self.client_event_handle.on_kick_off(prompt_info)

def on_transfer_complete(self):
self.client_event_handle.on_transfer_complete()

def on_call_global(self, method:str, hub_name:str, argvs:bytes):
_call_handle = self.__hub_global_callback__[method]
if _call_handle != None:
_call_handle(hub_name, argvs)
else:
print("unhandle global method:{}".format(method))

def register_global_method(self, method:str, callback:Callable[[str, bytes]]):
self.__hub_global_callback__[method] = callback

def connect_tcp(self, addr:str, port:int) -> bool:
return self.ctx.connect_tcp(addr, port)

def connect_ws(self, host:str) -> bool:
return self.ctx.connect_ws(host)

def connect_wss(self, host:str) -> bool:
return self.ctx.connect_wss(host)

def login(self, sdk_uuid:str) -> bool:
return self.ctx.login(sdk_uuid)

def reconnect(self, account_id:str, token:str) -> bool:
return self.ctx.reconnect(account_id, token)

def request_hub_service(self, service_name:str) -> bool:
return self.ctx.request_hub_service(service_name)

def register(self, entity_type:str, creator:Callable[[str, dict]]):
self.__entity_create_method__[entity_type] = creator
return self

def create_entity(self, entity_type:str, entity_id:str, argvs: dict):
_creator = self.__entity_create_method__[entity_type]
_creator(entity_id, argvs)

def update_entity(self, entity_type:str, entity_id:str, argvs: dict):
self.player_mgr.update_player(entity_id, argvs)
self.subentity_mgr.update_subentity(entity_id, argvs)
self.receiver_mgr.update_receiver(entity_id, argvs)

def delete_entity(self, entity_id:str):
self.player_mgr.del_player(entity_id)
self.subentity_mgr.del_subentity(entity_id)
self.receiver_mgr.del_receiver(entity_id)

def close(self):
self.__is_run__ = False

def poll_conn_msg(self):
while True:
if not self.__pump__.poll_conn_msg(self.__conn_handle__):
break

def poll(self):
while self.__is_run__:
start = time.time()
self.poll_conn_msg()
tick = time.time() - start
if tick < 0.033:
time.sleep(0.033 - tick)

def run(self):
self.poll()

6 changes: 6 additions & 0 deletions client/engine/base_entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: UTF-8 -*-

class base_entity(object):
def __init__(self, entity_type:str, entity_id:str) -> None:
self.entity_type = entity_type
self.entity_id = entity_id
23 changes: 23 additions & 0 deletions client/engine/callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: UTF-8 -*-
from collections.abc import Callable
from threading import Timer

class callback(object):
def __init__(self, release_handle:Callable[[],None]):
self._callback:Callable[[bytes],None] = None
self.error:Callable[[bytes],None] = None
self._timeout:Callable[[],None] = None

self.release_handle = release_handle

def callback(self, rsp_callback:Callable[[bytes],None], err_callback:Callable[[bytes],None]):
self._callback = rsp_callback
self.error = err_callback

def __call_timeout__(self):
self.release_handle()
self._timeout()

def timeout(self, _timeout:int, time_callback:Callable[[],None]):
self._timeout = time_callback
Timer(_timeout/1000, self.__call_timeout__).start()
77 changes: 77 additions & 0 deletions client/engine/conn_msg_handle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# -*- coding: UTF-8 -*-
from collections.abc import Callable
from .msgpack import *

class conn_msg_handle(object):
def on_create_remote_entity(self, entity_type:str, entity_id:str, argvs:bytes):
from app import app
app().create_entity(entity_type, entity_id, loads(argvs))

def on_delete_remote_entity(self, entity_id:str):
from app import app
app().delete_entity(entity_id)

def on_refresh_entity(self, entity_type:str, entity_id:str, argvs:bytes):
from app import app
app().update_entity(entity_type, entity_id, loads(argvs))

def on_kick_off(self, prompt_info:str):
from app import app
app().close()
app().on_kick_off(prompt_info)

def on_transfer_complete(self):
from app import app
app().on_transfer_complete()

def on_call_rpc(self, hub_name:str, entity_id:str, msg_cb_id:int, method:str, argvs:bytes):
from app import app
_player = app().player_mgr.get_player(entity_id)
if _player != None:
_player.handle_hub_request(method, hub_name, msg_cb_id, argvs)
return
print("unhandle hub request method:{} entity:{}".format(method, entity_id))

def on_call_rsp(self, entity_id:str, msg_cb_id:int, argvs:bytes):
from app import app
_player = app().player_mgr.get_player(entity_id)
if _player != None:
_player.handle_hub_response(msg_cb_id, argvs)
return
_subentity = app().subentity_mgr.get_subentity(entity_id)
if _subentity != None:
_subentity.handle_hub_response(msg_cb_id, argvs)
return
print("unhandle hub response msg_cb_id:{} entity:{}".format(msg_cb_id, entity_id))

def on_call_err(self, entity_id:str, msg_cb_id:int, argvs:bytes):
from app import app
_player = app().player_mgr.get_player(entity_id)
if _player != None:
_player.handle_hub_response_error(msg_cb_id, argvs)
return
_subentity = app().subentity_mgr.get_subentity(entity_id)
if _subentity != None:
_subentity.handle_hub_response_error(msg_cb_id, argvs)
return
print("unhandle hub response error msg_cb_id:{} entity:{}".format(msg_cb_id, entity_id))

def on_call_ntf(self, hub_name:str, entity_id:str, method:str, argvs:bytes):
from app import app
_player = app().player_mgr.get_player(entity_id)
if _player != None:
_player.handle_hub_notify(method, hub_name, argvs)
return
_subentity = app().subentity_mgr.get_subentity(entity_id)
if _subentity != None:
_subentity.handle_hub_notify(method, hub_name, argvs)
return
_receiver = app().receiver_mgr.get_receiver(entity_id)
if _receiver != None:
_receiver.handle_hub_notify(method, hub_name, argvs)
return
print("unhandle hub response notify msg_cb_id:{} entity:{}".format(method, entity_id))

def on_call_global(self, method:str, argvs:bytes):
from app import app
app().on_call_global(method, argvs)
36 changes: 36 additions & 0 deletions client/engine/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: UTF-8 -*-
from .pyclient import ClientContext

class context(object):
def __init__(self) -> None:
self.ctx = ClientContext()

def connect_tcp(self, addr:str, port:int) -> bool:
return self.ctx.connect_tcp(addr, port)

def connect_ws(self, host:str) -> bool:
return self.ctx.connect_ws(host)

def login(self, sdk_uuid:str) -> bool:
return self.ctx.login(sdk_uuid)

def reconnect(self, account_id:str, token:str) -> bool:
return self.ctx.reconnect(account_id, token)

def request_hub_service(self, service_name:str) -> bool:
return self.ctx.request_hub_service(service_name)

def call_rpc(self, entity_id:str, msg_cb_id:int, method:str, argvs:bytes) -> bool:
return self.ctx.call_rpc(entity_id, msg_cb_id, method, argvs)

def call_rsp(self, entity_id:str, msg_cb_id:int, argvs:bytes) -> bool:
return self.ctx.call_rsp(entity_id, msg_cb_id, argvs)

def call_err(self, entity_id:str, msg_cb_id:int, argvs:bytes) -> bool:
return self.ctx.call_err(entity_id, msg_cb_id, argvs)

def call_ntf(self, entity_id:str, method:str, argvs:bytes) -> bool:
return self.ctx.call_ntf(entity_id, method, argvs)

def poll_conn_msg(self, handle) -> bool:
return self.ctx.poll_conn_msg(handle)
Loading

0 comments on commit 43dab4b

Please sign in to comment.