Update app.py
Browse files
app.py
CHANGED
|
@@ -141,7 +141,11 @@ async def websocket_endpoint(
|
|
| 141 |
)
|
| 142 |
).strip()
|
| 143 |
|
| 144 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
await ws.send_text(
|
| 147 |
json.dumps({
|
|
@@ -225,6 +229,8 @@ async def websocket_endpoint(
|
|
| 225 |
except:
|
| 226 |
pass
|
| 227 |
|
|
|
|
|
|
|
| 228 |
for path, owner in (
|
| 229 |
entreprises_data.items()
|
| 230 |
):
|
|
@@ -241,7 +247,11 @@ async def websocket_endpoint(
|
|
| 241 |
# POSITION
|
| 242 |
# =====================================
|
| 243 |
|
| 244 |
-
elif
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
player_positions[
|
| 247 |
session_id
|
|
@@ -275,42 +285,15 @@ async def websocket_endpoint(
|
|
| 275 |
except:
|
| 276 |
pass
|
| 277 |
|
| 278 |
-
# =====================================
|
| 279 |
-
# CHAT
|
| 280 |
-
# =====================================
|
| 281 |
-
|
| 282 |
-
elif msg_type == "chat_message":
|
| 283 |
-
|
| 284 |
-
broadcast = {
|
| 285 |
-
"type":"chat_message",
|
| 286 |
-
"username":data.get(
|
| 287 |
-
"username",
|
| 288 |
-
"Unknown"
|
| 289 |
-
),
|
| 290 |
-
"message":data.get(
|
| 291 |
-
"message",
|
| 292 |
-
""
|
| 293 |
-
)
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
for client in clients.values():
|
| 297 |
-
|
| 298 |
-
try:
|
| 299 |
-
|
| 300 |
-
await client.send_text(
|
| 301 |
-
json.dumps(
|
| 302 |
-
broadcast
|
| 303 |
-
)
|
| 304 |
-
)
|
| 305 |
-
|
| 306 |
-
except:
|
| 307 |
-
pass
|
| 308 |
-
|
| 309 |
# =====================================
|
| 310 |
# MONEY
|
| 311 |
# =====================================
|
| 312 |
|
| 313 |
-
elif
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
if username:
|
| 316 |
|
|
@@ -329,26 +312,58 @@ async def websocket_endpoint(
|
|
| 329 |
# PROGRESS
|
| 330 |
# =====================================
|
| 331 |
|
| 332 |
-
elif
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
if username:
|
| 335 |
|
| 336 |
-
|
| 337 |
-
username
|
| 338 |
-
]["progress"] = int(
|
| 339 |
data.get(
|
| 340 |
"progress",
|
| 341 |
1
|
| 342 |
)
|
| 343 |
)
|
| 344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
save_players()
|
| 346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
# =====================================
|
| 348 |
-
#
|
| 349 |
# =====================================
|
| 350 |
|
| 351 |
-
elif
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
|
| 353 |
path = data.get(
|
| 354 |
"path",
|
|
@@ -370,7 +385,11 @@ async def websocket_endpoint(
|
|
| 370 |
# CHANGE OWNER
|
| 371 |
# =====================================
|
| 372 |
|
| 373 |
-
elif
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
path = data.get(
|
| 376 |
"path",
|
|
@@ -413,7 +432,7 @@ async def websocket_endpoint(
|
|
| 413 |
|
| 414 |
finally:
|
| 415 |
|
| 416 |
-
# Libération
|
| 417 |
|
| 418 |
to_clear = []
|
| 419 |
|
|
@@ -467,10 +486,6 @@ async def websocket_endpoint(
|
|
| 467 |
except:
|
| 468 |
pass
|
| 469 |
|
| 470 |
-
# ======================================================
|
| 471 |
-
# RUN
|
| 472 |
-
# ======================================================
|
| 473 |
-
|
| 474 |
if __name__ == "__main__":
|
| 475 |
|
| 476 |
port = int(
|
|
|
|
| 141 |
)
|
| 142 |
).strip()
|
| 143 |
|
| 144 |
+
if (
|
| 145 |
+
user == ""
|
| 146 |
+
or
|
| 147 |
+
password == ""
|
| 148 |
+
):
|
| 149 |
|
| 150 |
await ws.send_text(
|
| 151 |
json.dumps({
|
|
|
|
| 229 |
except:
|
| 230 |
pass
|
| 231 |
|
| 232 |
+
# Envoi des propriétaires des entreprises
|
| 233 |
+
|
| 234 |
for path, owner in (
|
| 235 |
entreprises_data.items()
|
| 236 |
):
|
|
|
|
| 247 |
# POSITION
|
| 248 |
# =====================================
|
| 249 |
|
| 250 |
+
elif (
|
| 251 |
+
msg_type
|
| 252 |
+
==
|
| 253 |
+
"player_update"
|
| 254 |
+
):
|
| 255 |
|
| 256 |
player_positions[
|
| 257 |
session_id
|
|
|
|
| 285 |
except:
|
| 286 |
pass
|
| 287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
# =====================================
|
| 289 |
# MONEY
|
| 290 |
# =====================================
|
| 291 |
|
| 292 |
+
elif (
|
| 293 |
+
msg_type
|
| 294 |
+
==
|
| 295 |
+
"save_money"
|
| 296 |
+
):
|
| 297 |
|
| 298 |
if username:
|
| 299 |
|
|
|
|
| 312 |
# PROGRESS
|
| 313 |
# =====================================
|
| 314 |
|
| 315 |
+
elif (
|
| 316 |
+
msg_type
|
| 317 |
+
==
|
| 318 |
+
"save_progress"
|
| 319 |
+
):
|
| 320 |
|
| 321 |
if username:
|
| 322 |
|
| 323 |
+
progress = int(
|
|
|
|
|
|
|
| 324 |
data.get(
|
| 325 |
"progress",
|
| 326 |
1
|
| 327 |
)
|
| 328 |
)
|
| 329 |
|
| 330 |
+
players_data[
|
| 331 |
+
username
|
| 332 |
+
]["progress"] = progress
|
| 333 |
+
|
| 334 |
save_players()
|
| 335 |
|
| 336 |
+
broadcast = {
|
| 337 |
+
"type":"player_progress",
|
| 338 |
+
"id":session_id,
|
| 339 |
+
"progress":progress
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
for sid, client in clients.items():
|
| 343 |
+
|
| 344 |
+
if sid == session_id:
|
| 345 |
+
continue
|
| 346 |
+
|
| 347 |
+
try:
|
| 348 |
+
|
| 349 |
+
await client.send_text(
|
| 350 |
+
json.dumps(
|
| 351 |
+
broadcast
|
| 352 |
+
)
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
except:
|
| 356 |
+
pass
|
| 357 |
+
|
| 358 |
# =====================================
|
| 359 |
+
# ENTREPRISE
|
| 360 |
# =====================================
|
| 361 |
|
| 362 |
+
elif (
|
| 363 |
+
msg_type
|
| 364 |
+
==
|
| 365 |
+
"save_entreprise"
|
| 366 |
+
):
|
| 367 |
|
| 368 |
path = data.get(
|
| 369 |
"path",
|
|
|
|
| 385 |
# CHANGE OWNER
|
| 386 |
# =====================================
|
| 387 |
|
| 388 |
+
elif (
|
| 389 |
+
msg_type
|
| 390 |
+
==
|
| 391 |
+
"set_entreprise_owner"
|
| 392 |
+
):
|
| 393 |
|
| 394 |
path = data.get(
|
| 395 |
"path",
|
|
|
|
| 432 |
|
| 433 |
finally:
|
| 434 |
|
| 435 |
+
# Libération entreprises
|
| 436 |
|
| 437 |
to_clear = []
|
| 438 |
|
|
|
|
| 486 |
except:
|
| 487 |
pass
|
| 488 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
if __name__ == "__main__":
|
| 490 |
|
| 491 |
port = int(
|