Skip to content

Commit

Permalink
Merge branch 'release/1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
albertowd committed Jul 9, 2018
2 parents 454e525 + 311553c commit 2275896
Show file tree
Hide file tree
Showing 38 changed files with 979 additions and 1,086 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
# Setup Share
# Setup Share 1.2
A simple App for sharing setups within Assetto Corsa sessions.

## App

The app works on saved Setups/Pit Strategies used by your car and track in the current session (online or single player). You can only download setups from other drivers in the session that are using the same car as you and already uploaded one setup.
The app works on saved setups/pit strategyies used by your car and track in the current session (online or single player). You can only download setups from other drivers that already uploaded their setups for the same combo.
![App screenshot.](https://raw.githubusercontent.com/albertowd/SetupShare/master/img/app.jpg)

### App Install
### App install

First unzip the release content direct on your assetto corsa main folder (C:/Program Files (x86)/steam/steamapps/common/assettocorsa) and load the game.
Select the option menu and the general sub menu. In the UI Module section will be listed this app to be checked.
Last step is to enter a session and select it on the right app bar to see it on screen.
Select the option menu and the general sub menu in-game to activate the SetupShare app. In the UI Module section will be listed this app to be checked.
![Enabling the app in-game.](https://raw.githubusercontent.com/albertowd/SetupShare/master/img/menu.gif)
Last step is to enter a session (online, practice, race..) and select it on the right app bar to see it on screen.

### Downloading and uploading

This app doesn't apply a downloaded setup automatically neither upload an unsaved one.
The first line of the app contains the list of the users computer setups. The selected setup can be uploaded to the system, updating it if it's already in "the cloud".
The rest of the view contains the list of uploaded setups groupped by users. Selecting one and downloading it will write or overwrite the setup on the users computer.
![Using the app.](https://raw.githubusercontent.com/albertowd/SetupShare/master/img/app.gif)

## Web

The [page](http://albertowd.com.br/setupshare/) shows all the uploaded setups, use the search filter to find and download one (.ini and .sp, if available). Uploads are only allowed through the app.
The [page](http://albertowd.com.br/setupshare/) shows all the uploaded setups, use the search filter to find and download one (.ini and .sp, if available). Uploads are only allowed through the app.

## Changelog

v 1.2:
* App: adapted to the handle the new server.
* Server: Chenged setups files to a database.
17 changes: 0 additions & 17 deletions app/apps/python/SetupShare/.project

This file was deleted.

8 changes: 0 additions & 8 deletions app/apps/python/SetupShare/.pydevproject

This file was deleted.

25 changes: 14 additions & 11 deletions app/apps/python/SetupShare/SetupShare.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Setup Share is a Python app to exchange seputs inside an Assetto Corsa session.
"""
import os
import platform
import sys
STD_LIB = "stdlib"

if platform.architecture()[0] == "64bit":
STD_LIB = "stdlib64"
sys.path.append(os.path.join(os.path.dirname(__file__), STD_LIB))
sys.path.append("apps/python/LiveTelemetry/stdlib64")
else:
sys.path.append("apps/python/LiveTelemetry/stdlib")
os.environ["PATH"] = os.environ["PATH"] + ";."

import ac
import ssconnection
from ssgui import Gui
from sslog import log
from lib.ss_connection import verify_server
from lib.ss_gui import Gui
from lib.ss_log import log

# Manage the GUI
GUI = Gui()
Expand All @@ -28,7 +31,7 @@ def acMain(ac_version):
ac.setIconPosition(GUI.app_window, 0, -10000)
ac.setSize(GUI.app_window, 400, 400)

lb_version = ac.addLabel(GUI.app_window, "v1.1")
lb_version = ac.addLabel(GUI.app_window, "v1.2")
ac.setPosition(lb_version, 10, 3)

GUI.bt_refresh = GUI.img_buttow("refresh")
Expand Down Expand Up @@ -110,7 +113,7 @@ def acMain(ac_version):
ac.setPosition(GUI.lb_status, 154, 370)
ac.setSize(GUI.lb_status, 236, 370)

if ssconnection.verify_server():
if verify_server():
GUI.set_status("Refresh app to start.")
else:
GUI.set_status("Server down, sorry.", True)
Expand All @@ -123,7 +126,7 @@ def acMain(ac_version):

def acShutdown():
""" Called when the session ends (or restarts). """
log("Shuting down Community Setup...")
log("Shuting down Setup Share...")
log("Success.")


Expand Down Expand Up @@ -307,7 +310,7 @@ def listener_refresh(*args):
global GUI
GUI.set_status("")
GUI.clear()
if ssconnection.verify_server():
if verify_server():
GUI.update_setups()
else:
GUI.set_status("Server down, sorry.", True)
Expand All @@ -318,4 +321,4 @@ def listener_upload(*args):
""" Upload the selected setup. """
global GUI
GUI.upload()
GUI.update()
GUI.update()
46 changes: 46 additions & 0 deletions app/apps/python/SetupShare/lib/ss_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Setup Share Connection utils.
"""
from json import dumps
from requests import get, post
import sys

SS_API_SERVER = "http://albertowd.com.br/setupshare/api"

def combo_list(car, track):
""" Gets the list os available setups of the car/track. """
global SS_API_SERVER
response = get("{}/list.php?app&car={}&track={}".format(SS_API_SERVER, car, track), timeout=5)
return response.json() if response.status_code == 200 else []


def download(setup_id, ext="ini"):
""" Downloads a specific setup. """
global SS_API_SERVER
response = get("{}/download.php?id={}&ext={}".format(SS_API_SERVER, setup_id, ext), timeout=5)
return response.text if response.status_code == 200 else None


def upload(setup):
""" Uploads the user setup. """
global SS_API_SERVER
return post("{}/upload.php".format(SS_API_SERVER), data=dumps(setup), timeout=5).text


def verify_server():
""" Verify the server connection. """
global SS_API_SERVER
return get("{}/download.php".format(SS_API_SERVER), timeout=5).status_code == 403


if __name__ == "__main__":
print("Server status: {}".format("on" if verify_server() else "off"))
CAR = "bmw_m3_gt2"
DRIVER = "Alberto Dietrich"
SETUP = "test"
TRACK = "spa"
#print(upload(CAR, DRIVER, "my ini content", SETUP, "my sp content", TRACK))
print(combo_list(CAR, TRACK))
print(download(1))
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Setup Share Document utils.
"""
Expand All @@ -16,7 +18,7 @@ def setup_dir():

def read_setup(car, setup, track, extension="ini"):
""" Returns the content of the setup .ini or .sp. """
content = ""
content = None
content_path = "{}/{}/{}/{}.{}".format(setup_dir(), car, track, setup, extension)
if os.path.isfile(content_path):
with open(content_path, "r") as content_file:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Setup Share Gui utils.
"""

import math

from lib.ss_connection import combo_list, download, upload
from lib.ss_documents import list_setups, read_setup, write_setup
from lib.ss_log import log
from sim_info.sim_info import info
import ac
import ssconnection
import ssdocuments
import sslog


class Driver:
Expand Down Expand Up @@ -41,7 +43,7 @@ def driver(self, index, page):
def driver_index(self, name):
""" Returns the driver index on the list. """
for driver_index in range(len(self.__drivers)):
if self.__drivers[driver_index].name is name:
if self.__drivers[driver_index].name == name:
return driver_index
return -1

Expand All @@ -68,9 +70,11 @@ def is_valid(self, page):
def update(self, setups):
""" Updates drivers setups. """
for setup in setups:
if self.driver_index(setup["driver"]) is -1:
driver_index = self.driver_index(setup["driver"])
if driver_index is -1:
self.__drivers.append(Driver(setup["driver"]))
self.__drivers[self.driver_index(setup["driver"])].setups.append(setup["name"])
driver_index = self.driver_index(setup["driver"])
self.__drivers[driver_index].setups.append((setup["id"], setup["name"]))

def update_setup(self, index, page_index, add=0):
""" Updates the driver setup index. """
Expand Down Expand Up @@ -120,15 +124,16 @@ def download(self, index):
if driver is not None:
setup = driver.setups[driver.current]
track = ac.getTrackName(0)
ini = ssconnection.download(car, driver.name, setup, track)
if len(ini) > 100:
ssdocuments.write_setup(car, ini, setup, track)
sp = ssconnection.download(car, driver.name, setup, track, "sp")
if len(sp) > 100:
ssdocuments.write_setup(car, sp, setup, track, "sp")
self.set_status("{} downloaded.".format(setup))
log("Downloading setup (car: {}, dirver: {}, name: {}, track: {})...".format(car, driver.name, setup[1], track))
ini = download(setup[0])
if ini != None:
write_setup(car, ini, setup[1], track)
sp = download(id, "sp")
if sp != None:
write_setup(car, sp, setup[1], track, "sp")
self.set_status("{} downloaded.".format(setup[1]))
else:
self.set_status(ini, True)
self.set_status("Download failed.", True)
else:
self.set_status("Invalid driver.", True)

Expand All @@ -141,6 +146,7 @@ def img_buttow(self, icon, width=24, height=24):

def set_status(self, message, error=False):
""" Sets the error or done status. """
log(message)
self.done = "" if error else message
self.error = message if error else ""

Expand All @@ -166,7 +172,7 @@ def update(self):

# Updates the setup, change and download buttons.
has_setup = len(driver.setups) > 0
ac.setText(self.list[index]["setup"], "" if len(driver.setups) == 0 else driver.setups[driver.current])
ac.setText(self.list[index]["setup"], "" if len(driver.setups) == 0 else driver.setups[driver.current][1])
ac.setVisible(self.list[index]["change"], 1 if has_setup else 0)
ac.setVisible(self.list[index]["download"], 1 if has_setup else 0)

Expand Down Expand Up @@ -213,23 +219,31 @@ def update_setups(self):
car = ac.getCarName(0)
track = ac.getTrackName(0)
# Updates the user setups.
self.driver.setups = ssdocuments.list_setups(car, track)
self.driver.setups = list_setups(car, track)
self.update_setup()

# Updates the drivers setups.
self.drivers.clear()
setups = ssconnection.available(car, track)
if isinstance(setups, list):
self.drivers.update(setups)
log("Updating setup list from server (car: {}, track: {})...".format(car, track))
setups = combo_list(car, track)
log("{} setup(s) found.".format(len(setups)))
self.drivers.update(setups)

def upload(self):
""" Uploads the current setup to the server. """
car = ac.getCarName(0)
setup = self.driver.setups[self.driver.current]
track = ac.getTrackName(0)
ini_content = ssdocuments.read_setup(car, setup, track)
sp_content = ssdocuments.read_setup(car, setup, track, "sp")
if len(ini_content) == 0:
name = self.driver.setups[self.driver.current]
ini_content = read_setup(ac.getCarName(0), name, ac.getTrackName(0))
if ini_content == None:
self.set_status("Invalid setup.", True)
else:
self.set_status(ssconnection.upload(car, self.driver.name, ini_content, setup, sp_content, track))
setup = {}
setup["ac_version"] = info.static._acVersion
setup["car"] = ac.getCarName(0)
setup["driver"] = self.driver.name
setup["ini"] = ini_content
setup["name"] = name
setup["sp"] = read_setup(ac.getCarName(0), name, ac.getTrackName(0), "sp")
setup["track"] = ac.getTrackName(0)
log("Uploading setup {}...".format(name))
upload_response = upload(setup)
self.set_status(upload_response, "not" in upload_response)
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Setup Share Log utils.
"""
Expand Down
Loading

0 comments on commit 2275896

Please sign in to comment.