Skip to content

Commit

Permalink
Friends' profile pictures. Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidCaos committed Jan 20, 2024
1 parent e7712e5 commit 40212b4
Show file tree
Hide file tree
Showing 8 changed files with 9,074 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ saves/
new_assets/
tools/unit_patch_storage.json
auctions/auctions.json
build/bundle
build/dist
build/work
7 changes: 5 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
if os.name == 'nt':
os.system("color")
os.system("title Social Wars Server")
else:
import sys
sys.stdout.write("\x1b]2;Social Wars Server\x07")

print (" [+] Loading game config...")
from get_game_config import get_game_config

print (" [+] Loading players...")
from get_player_info import get_player_info, get_neighbor_info
from sessions import load_saves, load_static_villages, load_quests, all_saves_userid, all_saves_info, save_info, new_village
from sessions import load_saves, load_static_villages, load_quests, all_saves_userid, all_saves_info, save_info, new_village, fb_friends_str
load_saves()
print (" [+] Loading static villages...")
load_static_villages()
Expand Down Expand Up @@ -83,7 +86,7 @@ def play():
GAMEVERSION = session['GAMEVERSION']
print("[PLAY] USERID:", USERID)
print("[PLAY] GAMEVERSION:", GAMEVERSION)
return render_template("play.html", save_info=save_info(USERID), serverTime=timestamp_now(), version=version_name, GAMEVERSION=GAMEVERSION, SERVERIP=host, SERVERPORT=port)
return render_template("play.html", save_info=save_info(USERID), serverTime=timestamp_now(), friendsInfo=fb_friends_str(USERID), version=version_name, GAMEVERSION=GAMEVERSION, SERVERIP=host, SERVERPORT=port)

@app.route("/new.html")
def new():
Expand Down
69 changes: 47 additions & 22 deletions sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import uuid
import random
from flask import session
# from flask_session import SqlAlchemySessionInterface, current_app

from version import version_code
from engine import timestamp_now
Expand Down Expand Up @@ -138,7 +137,6 @@ def all_saves_userid() -> list:
def all_userid() -> list:
"Returns a list of the USERID of every village."
return list(__villages.keys()) + list(__saves.keys()) + list(__quests.keys())
# return [i["playerInfo"]["pid"] for i in __villages] + [i["playerInfo"]["pid"] for i in __quests] + [i["playerInfo"]["pid"] for i in __saves]

def save_info(USERID: str) -> dict:
save = __saves[USERID]
Expand Down Expand Up @@ -167,32 +165,59 @@ def neighbor_session(USERID: str) -> dict:
if USERID in __villages:
return __villages[USERID]

def fb_friends_str(USERID: str) -> list:
friends = []
# static villages
for key in __villages:
vill = __villages[key]
if vill["playerInfo"]["pid"] == "100000030" \
or vill["playerInfo"]["pid"] == "100000031": # general Mike
continue
frie = {}
frie["uid"] = vill["playerInfo"]["pid"]
frie["pic_square"] = vill["playerInfo"]["pic"]
friends += [frie]
# other players
for key in __saves:
vill = __saves[key]
if vill["playerInfo"]["pid"] == USERID:
continue
frie = {}
frie["uid"] = vill["playerInfo"]["pid"]
frie["pic_square"] = vill["playerInfo"]["pic"]
friends += [frie]
return friends

def neighbors(USERID: str):
neighbors = []
# static villages
# for key in __villages:
# vill = __villages[key]
# if vill["playerInfo"]["pid"] != '100000030': # general Mike
# neigh = vill["playerInfo"]
# neigh["xp"] = vill["maps"][0]["xp"]
# neigh["level"] = vill["maps"][0]["level"]
# neigh["gold"] = vill["maps"][0]["gold"]
# neigh["wood"] = vill["maps"][0]["wood"]
# neigh["oil"] = vill["maps"][0]["oil"]
# neigh["steel"] = vill["maps"][0]["steel"]
# neighbors += [neigh]
for key in __villages:
vill = __villages[key]
if vill["playerInfo"]["pid"] == "100000030" \
or vill["playerInfo"]["pid"] == "100000031": # general Mike
continue
neigh = vill["playerInfo"]
neigh = json.loads(json.dumps(vill["playerInfo"]))
neigh["xp"] = vill["maps"][0]["xp"]
neigh["level"] = vill["maps"][0]["level"]
neigh["gold"] = vill["maps"][0]["gold"]
neigh["wood"] = vill["maps"][0]["wood"]
neigh["oil"] = vill["maps"][0]["oil"]
neigh["steel"] = vill["maps"][0]["steel"]
neighbors += [neigh]
# other players
for key in __saves:
vill = __saves[key]
if vill["playerInfo"]["pid"] != USERID:
neigh = json.loads(json.dumps(vill["playerInfo"])) # Stop clogging up playerInfo when just wanting to send some data from save from a neighbour
neigh["xp"] = vill["maps"][0]["xp"]
neigh["level"] = vill["maps"][0]["level"]
neigh["gold"] = vill["maps"][0]["gold"]
neigh["wood"] = vill["maps"][0]["wood"]
neigh["oil"] = vill["maps"][0]["oil"]
neigh["steel"] = vill["maps"][0]["steel"]
neighbors += [neigh]
if vill["playerInfo"]["pid"] == USERID:
continue
neigh = json.loads(json.dumps(vill["playerInfo"])) # Stop clogging up playerInfo when just wanting to send some data from save from a neighbour
neigh["xp"] = vill["maps"][0]["xp"]
neigh["level"] = vill["maps"][0]["level"]
neigh["gold"] = vill["maps"][0]["gold"]
neigh["wood"] = vill["maps"][0]["wood"]
neigh["oil"] = vill["maps"][0]["oil"]
neigh["steel"] = vill["maps"][0]["steel"]
neighbors += [neigh]
return neighbors

# Check for valid village
Expand Down
2 changes: 1 addition & 1 deletion templates/play.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
&sex=m&brk=0
&lastLoggedIn=1349266517&brk=0
&dailyBonus=0&brk=0
&friendsInfo=[{"first_name":"AcidCaos","uid":"100000","pic_square":"http://{{SERVERIP}}:{{SERVERPORT}}/img/profile/x.jpg"}]&brk=0
&friendsInfo={{friendsInfo | tojson}}&brk=0
&serverTime={{serverTime}}&brk=0
&forceSyncError=1&brk=0
&forceAttackReload=0&brk=0
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def migrate_loaded_save(save: dict):

# 0.01a saves
_changed = False
if "version" not in save:
if "version" not in save or save["version"] is None:
_changed = True
save["version"] = "0.01a"
print(" [!] Applied version to save")
Expand Down
Loading

0 comments on commit 40212b4

Please sign in to comment.