Compare commits

...

7 Commits

Author SHA1 Message Date
603a169c39 Windows folders :( 2023-05-16 21:33:25 +02:00
a9db65f8b6 cleanup 2023-05-16 21:12:22 +02:00
f1ce1bff30 actually fixed readme 2023-05-16 21:11:51 +02:00
7ea995f1ec fixed readme 2023-05-16 21:11:29 +02:00
cee70ab57d Added timouts and ready to ship ver 1.1.1 :party: 2023-05-16 21:10:07 +02:00
d66becf13a Merge branch 'main' of dumtaxat-git:boyan_k/customm 2023-05-16 17:59:51 +03:00
e61029fdf5 Small change in server 2023-05-16 17:59:48 +03:00
10 changed files with 83 additions and 61 deletions

14
.gitignore vendored
View File

@ -1,10 +1,22 @@
# Config
config.ini config.ini
# Environment
.env/ .env/
# Database
db.sqlite3 db.sqlite3
# Build garbage
__pycache__/ __pycache__/
migrations/ migrations/
build/ build/
dist/ dist/
main.spec
# VSCode garbage
.vscode/ .vscode/
src/client/riotgames.pem # LCU_connector leftover
riotgames.pem
test.py

View File

@ -1,6 +1,8 @@
# custoMM # custoMM
<p align="center"> <p align="center">
<img src="images/logo.png"/> <img src="images/logo.png"/><br>
<img alt="Python => 3.11" src="https://img.shields.io/badge/Python-%3E%3D3.11-green)"/>
<img alt="Version 1.1.1" src="https://img.shields.io/badge/Version-1.1.1-blueviolet" />
</p> </p>

View File

@ -1,25 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIEIDCCAwgCCQDJC+QAdVx4UDANBgkqhkiG9w0BAQUFADCB0TELMAkGA1UEBhMC
VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFTATBgNVBAcTDFNhbnRhIE1vbmljYTET
MBEGA1UEChMKUmlvdCBHYW1lczEdMBsGA1UECxMUTG9MIEdhbWUgRW5naW5lZXJp
bmcxMzAxBgNVBAMTKkxvTCBHYW1lIEVuZ2luZWVyaW5nIENlcnRpZmljYXRlIEF1
dGhvcml0eTEtMCsGCSqGSIb3DQEJARYeZ2FtZXRlY2hub2xvZ2llc0ByaW90Z2Ft
ZXMuY29tMB4XDTEzMTI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dKD8cpgiWJk3L
XWehWA==
-----END CERTIFICATE-----

View File

@ -13,12 +13,25 @@ SITE_URL = "your-server.com"
``` ```
## Releases ## Releases
Check out the releases for pre-compiled binaries of the client and server. Check out the releases for pre-compiled binaries/installers of the client. Remember to edit the config.ini file before running. That will be done in the setup, but still.
## TODOs ## Manual compilationn
Compile the client like so.
1. [x] Make the server and client talk to each other Firstly, check if your Python version is => 3.11
* [x] Based on MMR ```
* [x] Based on cached IDs $ python --version
> Python 3.11.3
```
Then, clone the repository.
`$ git clone https://github.com/confestim/custoMM`
`$ cd custoMM/src/client`
If you don't have pyinstaller installed, do:
`$ pip install pyinstaller`
Once that's ready, you're ready to compile!
`$ python -m PyInstaller --onefile main.py`
The exe file will reside in the newly created dist/ folder. Don't forget to copy the assets and the config to the same folder that your EXE resides(that means you will have to send them over to your friends along with the EXE file):
`cp assets ../config.ini dist`

View File

@ -59,9 +59,11 @@ class Game:
# Starts champ select # Starts champ select
return self.connection.post("/lol-lobby/v1/lobby/custom/start-champ-select", data={}) return self.connection.post("/lol-lobby/v1/lobby/custom/start-champ-select", data={})
def move(self, team:str): def move(self):
return self.connection.post("/lol-lobby/v1/lobby/custom/switch-teams", data={}) return self.connection.post("/lol-lobby/v1/lobby/custom/switch-teams", data={})
def leave(self):
return self.connection.delete("/lol-lobby/v2/lobby")
def get_teams(self): def get_teams(self):
# Gets team # Gets team
cfg = self.connection.get("/lol-lobby/v2/lobby").json()["gameConfig"] cfg = self.connection.get("/lol-lobby/v2/lobby").json()["gameConfig"]

View File

@ -1,16 +1,23 @@
from time import sleep from time import sleep
from threading import Thread from threading import Thread
from .Scraper import Scraper from .Scraper import Scraper
import logging
class PeriodicScraper(Thread): class PeriodicScraper(Thread):
def __init__(self): def __init__(self):
Thread.__init__(self) Thread.__init__(self)
self.daemon = True self.daemon = True
self.connector:Scraper = Scraper() self.connector:Scraper = Scraper()
self.start() self.closed = False
def run(self): def run(self):
self.connector.check_for_game()
while True: while True:
if self.closed:
self.connector.connection.stop()
break
game_state = self.connector.check_for_game()
logging.info("Scraping...")
self.connector.scrape() self.connector.scrape()
sleep(5 * 60) sleep(5)

View File

@ -1,6 +1,6 @@
from lcu_connector import Connector from lcu_connector import Connector
from lcu_connector.exceptions import ClientProcessError from lcu_connector.exceptions import ClientProcessError
import asyncio import logging
import requests import requests
import time, sys import time, sys
import json import json
@ -20,7 +20,8 @@ class Scraper:
while not self.connection: while not self.connection:
try: try:
self.connection = Connector(start=True) self.connection = Connector()
self.connection.start()
except ClientProcessError: except ClientProcessError:
print("League client not open, sleeping...") print("League client not open, sleeping...")
time.sleep(90) time.sleep(90)
@ -127,7 +128,7 @@ class Scraper:
# Case 2: It belongs to somebody # Case 2: It belongs to somebody
if claimed['lol_id'] and claimed['lol']: if claimed['lol_id'] and claimed['lol']:
# Notify them (if that is the case) that we will do nothing about their new name (slight TODO). # Change name in db if different in-game
if claimed['lol'] != self.summoner['displayName']: if claimed['lol'] != self.summoner['displayName']:
self.register_summoner(True, claimed) self.register_summoner(True, claimed)
@ -148,23 +149,31 @@ class Scraper:
# This is buggy, try to find a better way to do this. # This is buggy, try to find a better way to do this.
# Like for example, letting team 1 pass first, and then team 2. # Like for example, letting team 1 pass first, and then team 2.
local_teams = game.get_teams() local_teams = game.get_teams()
print(local_teams[0], local_teams[1], checker["teams"][0], checker["teams"][1])
if name in local_teams[0] and not name in checker["teams"][0]: if name in local_teams[0] and not name in checker["teams"][0]:
game.move("blue") game.move()
print("blue") logging.info("Moving to Team 2")
elif name in local_teams[1] and not name in checker["teams"][1]: elif name in local_teams[1] and not name in checker["teams"][1]:
game.move("red") game.move()
print("red") logging.info("Moving to Team 1")
def start(self, checker, game): def start(self, checker, game):
self.move_needed(checker, game, self.name) self.move_needed(checker, game, self.name)
time.sleep(5) time.sleep(5)
# Wait until there are 10 players(confirmed) in the lobby # Wait until there are 10 players(confirmed) in the lobby
while requests.get(f"{self.URL}/current/{self.name}").json()["players"] != 10: timeout_counter = 0
print("Waiting for players...") while response := requests.get(f"{self.URL}/current/{self.name}").json()["players"] != 10:
logging.info("Waiting for players...")
timeout_counter += 5
if timeout_counter == 60:
logging.info("Timeout, aborting...")
break
time.sleep(5) time.sleep(5)
game.start() if response == 10:
logging.info("Starting game...")
game.start()
else:
game.leave()
requests.delete(f"{self.URL}/current/{self.name}") requests.delete(f"{self.URL}/current/{self.name}")
def check_for_game(self): def check_for_game(self):
@ -246,5 +255,4 @@ class Scraper:
if req.status_code == 500: if req.status_code == 500:
print("Serverside error! Contact maintainer!") print("Serverside error! Contact maintainer!")
self.connection.stop()
return len(games) return len(games)

View File

@ -1,15 +1,15 @@
import pystray import pystray
from PIL import Image from PIL import Image
from .Scraper import Scraper from .Scraper import Scraper
image = Image.open("assets/icon.png")
import pyautogui import pyautogui
from time import sleep from time import sleep
import logging
class UI(): class UI():
def __init__(self,scraper): def __init__(self,scraper, periodic, parent):
image = Image.open(parent + "\\assets\\icon.png")
self.periodic = periodic
self.menu = pystray.Menu( self.menu = pystray.Menu(
pystray.MenuItem( pystray.MenuItem(
"Check registration", self.check_registration, default=True "Check registration", self.check_registration, default=True
@ -30,6 +30,7 @@ class UI():
self.check_registration() self.check_registration()
self.icon.run_detached() self.icon.run_detached()
def check(self): def check(self):
self.icon.notify("This is discouraged, as it is done automatically anyway.", "Checking for game...") self.icon.notify("This is discouraged, as it is done automatically anyway.", "Checking for game...")
game = self.scraper.check_for_game() game = self.scraper.check_for_game()
@ -42,7 +43,6 @@ class UI():
def report(self): def report(self):
self.icon.notify("Game report initiated.") self.icon.notify("Game report initiated.")
logging.warning(self.icon)
self.scraper.scrape() self.scraper.scrape()
self.icon.notify("Game reported", "Your game has been reported to the server.") self.icon.notify("Game reported", "Your game has been reported to the server.")
@ -65,4 +65,5 @@ class UI():
def quit(self, icon, query): def quit(self, icon, query):
icon.stop() icon.stop()
self.periodic.closed = True

View File

@ -2,9 +2,10 @@ import requests
# Edit config.ini when running for the first time # Edit config.ini when running for the first time
import sys import sys
import os
import configparser import configparser
from time import sleep from time import sleep
import threading import logging
# Custom imports # Custom imports
from classes.Util import WhatTheFuckDidYouDo from classes.Util import WhatTheFuckDidYouDo
@ -13,9 +14,12 @@ from classes.PeriodicScraper import PeriodicScraper
from classes.Scraper import Scraper from classes.Scraper import Scraper
# Config section # Config section
parent = os.path.dirname(os.path.abspath(__file__))
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read("../config.ini") logging.info(parent + "\\config.ini")
print(parent + "\\config.ini")
URL = config["DEFAULT"]["URL"] URL = config["DEFAULT"]["URL"]
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
# Test connection to server # Test connection to server
try: try:
@ -31,12 +35,11 @@ except Exception:
def main(): def main():
# Match scraping # Match scraping
# Running the UI # Running the UI
ui = UI(scraper=Scraper())
scraper = Scraper(ui=ui)
periodic = PeriodicScraper() periodic = PeriodicScraper()
ui = UI(scraper=periodic.connector, periodic=periodic, parent=parent)
periodic.start()
periodic.join()
# Loop until close, let stuff kill itself
while threading.active_count() >= 3:
sleep(10)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -54,8 +54,7 @@ class CurrentViewSet(viewsets.ModelViewSet):
return Response(serializer.data) return Response(serializer.data)
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
discord_id = kwargs.get('pk') instance = Current.objects.get(creator=request.data.get("creator"))
instance = Current.objects.get(creator=creator)
self.perform_destroy(instance) self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)