This repository was archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
132 lines (121 loc) · 4.47 KB
/
client.py
File metadata and controls
132 lines (121 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Hello World client in Python
# Connects REQ socket to tcp://localhost:5555
# Sends "Hello" to server, expects "World" back
#
import zmq
import gg_lib as gg
import time
name_pl = "Admin" # Nom de la plateforme
check = True
error = 0
AdminCommands = ["update", "add", "value", "gems", "spinelles", "balance total", "playerid"]
REQUEST_TIMEOUT = 2500
REQUEST_RETRIES = 3
SERVER_ENDPOINT = "tcp://localhost:5555"
context = zmq.Context(1)
# Socket to talk to server
print("Connecting to Get Gems server…")
socket = context.socket(zmq.REQ)
socket.connect(SERVER_ENDPOINT)
# TIMEOUT
poll = zmq.Poller()
poll.register(socket, zmq.POLLIN)
socket.send_string(gg.std_send_command("GGconnect", "__client", name_pl))
time.sleep(1)
socks = dict(poll.poll(REQUEST_TIMEOUT))
if socks.get(socket) == zmq.POLLIN:
msg = socket.recv()
if msg.decode() == "1":
print("Connected to Get Gems server")
else:
print("Aucune réponse du serveur")
check = False
# Socket is confused. Close and remove it.
socket.setsockopt(zmq.LINGER, 0)
socket.close()
poll.unregister(socket)
while check:
print("\nCommande:")
x = input()
x = x.lower()
if x == "stop":
check = False
else:
if x == "stop server":
socket.send_string(gg.std_send_command("stop", "admin", name_pl))
elif x == "commands" or x == "help" or x == "?":
print("=====================================")
print("======== Liste des commandes ========")
print("\n=== Commandes générales ===")
print("• commands")
print("• stop")
print("• stop server")
print("\n=== Commandes administrateur ===")
for c in AdminCommands:
print("• {}".format(c))
print("=====================================")
elif x in AdminCommands:
param = dict()
param["fct"] = x.lower()
param["ID"] = 620558080551157770
param["arg2"] = "None"
param["arg3"] = "None"
param["arg4"] = "None"
print("==========================\n===== Admin Commands =====\n==========================\n")
if x != "balance total" and x != "playerid":
print("• PlayerID:")
param["ID"] = input()
if x == "update":
# arg2 = nameDB | arg3 = fieldName | arg4 = fieldValue
print("\n• nameDB:")
param["arg2"] = input()
print("\n• fieldName:")
param["arg3"] = input()
print("\n• fieldValue:")
param["arg4"] = input()
elif x == "add":
# arg2 = nameDB | arg3 = nameElem | arg4 = nbElem
print("nameDB:")
param["arg2"] = input()
print("\n• nameElem:")
param["arg3"] = input()
print("\n• nbElem:")
param["arg4"] = input()
elif x == "value":
# arg2 = nameDB | arg3 = nameElem
print("\n• nameDB:")
param["arg2"] = input()
print("\n• nameElem:")
param["arg3"] = input()
elif x == "gems":
# arg2 = nb gems
print("\n• Nombre de gems à ajouter:")
param["arg2"] = input()
elif x == "spinelles":
# arg2 = nb spinelles
print("Nombre de spinelles à ajouter:")
param["arg2"] = input()
elif x == "playerid":
print("• Platforme:")
param["arg2"] = input()
print("\n• ID du joueur sur la platforme:")
param["ID"] = input()
socket.send_string(gg.std_send_command("admin", 620558080551157770, name_pl, param))
elif x == "test":
print("> test")
# Get the reply.
socks = dict(poll.poll(REQUEST_TIMEOUT))
if socks.get(socket) == zmq.POLLIN:
message = gg.std_receive_command(socket.recv())
print(message['msg'])
else:
print("Aucune réponse du serveur")
# Socket is confused. Close and remove it.
socket.setsockopt(zmq.LINGER, 0)
socket.close()
poll.unregister(socket)
# Create new connection
socket = context.socket(zmq.REQ)
socket.connect(SERVER_ENDPOINT)
poll.register(socket, zmq.POLLIN)