Skip to content

Commit

Permalink
Update: Added pycli
Browse files Browse the repository at this point in the history
  • Loading branch information
i0gan committed Apr 28, 2024
1 parent 1021498 commit 52fc686
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
/src/lua/proto/code.lua
/src/lua/proto/enum.lua
/src/lua/struct/excel.lua
/src/pycli/proto
# Codeblocks
*.layout
*.depend
Expand Down Expand Up @@ -88,3 +89,4 @@ src/proto/msg_id.proto
src/struct/msg_id.h
src/struct/msg_id.cc
src/proto/n_msg_id.proto
src/pycli/login.cookie
Empty file added src/pycli/logic.py
Empty file.
75 changes: 75 additions & 0 deletions src/pycli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# python3
import requests
import requests.utils
import http.cookiejar as cookiejar
import json
import websocket
import _thread
import time
import rel
# pip install websocket-client websocket rel
# pip install requests
# pip install http

print("pycli:")

session = requests.session()
session.cookies = cookiejar.LWPCookieJar(filename='./login.cookie')
BaseUrl = 'http://127.0.0.1:8088'
header = {
'Referer': BaseUrl + "login",
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) Chrome/89.0.4389.82'
}

def login(account, password):
try:
login_data = {
'LoginType': 0,
'account': account,
'password': password,
'device' : 'pycli'
}
resp = session.post(url=BaseUrl + '/login', headers=header, data=json.dumps(login_data))
if resp.status_code == requests.codes.ok:
cookie = requests.utils.dict_from_cookiejar(session.cookies)
session.cookies.save(ignore_discard=True, ignore_expires=True)
return False, resp.text
return True, None
except Exception as ex:
print(ex)
return True, None

def on_message(ws, message):
print(message)

def on_error(ws, error):
print(error)

def on_close(ws, close_status_code, close_msg):
print("### closed ###")

def on_open(ws):
print("Opened connection")


if __name__ == '__main__':
# login
err, rsp = login("pycli", "password")
if (err):
exit()

print("login rsp: " + rsp)
jrsp = json.loads(rsp)
wsUrl = 'ws://' + str(jrsp['ip']) + ':' + str(jrsp['ws_port']) + '/'
print("connect to proxy: " + wsUrl)
ws = websocket.WebSocketApp(wsUrl,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)

rel.signal(2, rel.abort) # Keyboard Interrupt
rel.dispatch()

# Set dispatcher to automatic reconnection, 5 second reconnect delay if connection closed unexpectedly
ws.run_forever(dispatcher=rel, reconnect=5)
5 changes: 0 additions & 5 deletions third_party/install_boost.bat

This file was deleted.

5 changes: 5 additions & 0 deletions tools/proto2code.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ set proto_bin=..\third_party\build\bin\protoc
set proto_path="..\src\proto"
set cpp_out_path="..\src\struct"
set csharp_out_path="..\client\proto\csharp"
set python_out_path="..\src\pycli\proto"
set lua_out_path=""

mkdir %csharp_out_path%
mkdir %python_out_path%

rem Client's lua proto path
mkdir ..\client\proto\lua

Expand All @@ -22,6 +26,7 @@ python proto_to_lua_str.py
cd ..

for %%f in (%proto_path%\*.proto) do %proto_bin% --csharp_out=%csharp_out_path% --proto_path=%proto_path% %%f
for %%f in (%proto_path%\*.proto) do %proto_bin% --python_out=%python_out_path% --proto_path=%proto_path% %%f
rem windows dll于linux so有所区别,windows在需要声明导出函数,才能让其他dll或程序进行调用 参考 https://www.cnblogs.com/zhongpan/p/8378825.html
for %%f in (%proto_path%\*.proto) do %proto_bin% --cpp_out=dllexport_decl="WIN_DLL_EXPORT":%cpp_out_path% --proto_path=%proto_path% %%f

Expand Down
3 changes: 3 additions & 0 deletions tools/proto2code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ proto_bin='../third_party/build/bin/protoc'
proto_path="../src/proto"
cpp_out_path="../src/struct"
csharp_out_path='../client/proto/csharp'
python_out_path='../src/pycli/proto'
lua_out_path="../client/proto/lua"

mkdir -p $csharp_out_path
mkdir -p $python_out_path
mkdir -p $lua_out_path

# 生成Lua文件
Expand All @@ -33,6 +35,7 @@ do
echo $f
$proto_bin --cpp_out=$cpp_out_path --proto_path=$proto_path $f
$proto_bin --csharp_out=$csharp_out_path --proto_path=$proto_path $f
$proto_bin --cpython_out=$python_out_path --proto_path=$proto_path $f
check_err
done

Expand Down

0 comments on commit 52fc686

Please sign in to comment.