Skip to content

Commit 03fa643

Browse files
committed
First commit!
0 parents  commit 03fa643

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2521
-0
lines changed

Docker/build.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
lang="$1"
2+
3+
cd $lang
4+
5+
echo "Building $lang""...";
6+
7+
docker build \
8+
--no-cache \
9+
--rm \
10+
-t codingame-$lang \
11+
.

Docker/launchvm.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/zsh
2+
# ========
3+
4+
# Get the lang and extract the test program and the extension
5+
lang=$(echo "$1" | tr 'A-Z' 'a-z')
6+
nb_inputs=$2
7+
tmpDir="$3"
8+
9+
# Go to the test directory
10+
cd tmp/$tmpDir
11+
echo $tmpDir
12+
pwd
13+
# Copy the script to launch programs
14+
cp ../../Docker/$lang/launch.sh .
15+
16+
17+
18+
# Run the docker
19+
timeout --preserve-status -s 9 60 \
20+
docker run \
21+
--mount type=bind,source=`pwd`,target=/tmp/in,ro \
22+
--mount type=bind,source=`pwd`,target=/tmp/out \
23+
--memory 512mb \
24+
--network none \
25+
--name codingame-$lang-$$ --rm \
26+
"codingame-$lang"":latest" /bin/sh /tmp/in/launch.sh $(( $nb_inputs - 1 ))

Docker/python/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM python:3.9.12-alpine

Docker/python/launch.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Get the number of test from args
2+
countNbTest=$1
3+
4+
# Change directory
5+
cd /tmp/in
6+
7+
# Support errors
8+
set +e
9+
for testcount in `seq 0 1 $countNbTest`; do
10+
python prog.py \
11+
< /tmp/in/in$testcount.txt \
12+
> /tmp/out/got$testcount.txt \
13+
2> /tmp/out/err$testcount.txt
14+
done

Docker/ruby/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM ruby:3.1.2-alpine

Docker/ruby/launch.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Get the number of test from args
2+
countNbTest=$1
3+
4+
# Change directory
5+
cd /tmp/in
6+
7+
# Support errors
8+
set +e
9+
for testcount in `seq 0 1 $countNbTest`; do
10+
ruby prog.rb \
11+
< /tmp/in/in$testcount.txt \
12+
> /tmp/out/got$testcount.txt \
13+
2> /tmp/out/err$testcount.txt
14+
done

README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# <p style='text-align: center; margin: 0; padding: 0'>CustomCodinGameClient</p>
2+
3+
This codingame client is not fully replaceable by the original codingame client.
4+
It is, for the moment, complementary to the original website.
5+
6+
Here is what this client adds:
7+
8+
- A shorter version of python for fastest and reverse. This modified version of python, modifies the AST of your original code to add, transform some built-in classes like int, list or str into an extended version of these classes.
9+
- A way to test the code locally (without hidden test cases) by simply pressing a key, [RSHIFT] (by default). As well as a way to submit the code to the server by pressing a key [RCTRL] (by default)
10+
- A way to automatically receive the problem you are facing with a more sober HTML and a more basic display, which always shows the test cases you missed first.
11+
12+
13+
## How does it work?
14+
### Shorter python
15+
As said before, there is a "modified" version of python in this client. But what makes it useful, is that it's also written in python and therefore it's possible to translate the code of the modified version of the code, to a real python code.
16+
17+
All that logic is made in `translate_ast.py`.
18+
19+
In this shorter python there is also some new built-ins functions and some operators have new meanings.
20+
21+
For example `0@10` is the same as `range(0,10)`. (Operators overloading in python are annoying, so I wasn't able to overload `:` for example.)
22+
23+
- In `prog.py` it's the program that you write
24+
- In `classes.py` is everything related to the modified classes.
25+
- In `default_values.py` there are a lot of built-ins default_values.
26+
- In `functions.py` there is everything related to the functions.
27+
- In `translate_ast.py` the program modifies the AST of prog.py, default_values.py and functions.py. After that, it merges all of them, and add classes.py at the top, with some extra text. And now... the program is a valid python program!
28+
- In `./test/*` there are all the files that tests a function. You can run all the tests with `./test_all.sh`
29+
30+
If you don't want to read all the code, you can read `documentation.md` that explain all the new features of this Python superset.
31+
32+
## Installation
33+
The installation isn't the easiest part.
34+
There are a lot of things to do for that client to work.
35+
36+
### Docker
37+
To test the code locally, you will have to install docker, to run the programs in a new environment that is always the same.
38+
39+
Debian:
40+
```sh
41+
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
42+
```
43+
44+
Arch:
45+
```sh
46+
sudo pacman -S docker
47+
```
48+
49+
Gentoo:
50+
```sh
51+
sudo emerge -av app-emulation/docker
52+
```
53+
54+
After that, you will need to build the Dockerfiles.
55+
In `./Docker` there is a `build.sh` program.
56+
You can just do `./Docker/build.sh <lang>` with lang being python or ruby.
57+
58+
### Python libraries
59+
You will also have to install libraries for the programs to work.
60+
All the required librairies are in REQUIREMENTS.txt.
61+
You can install them with
62+
```sh
63+
pip install -r REQUIREMENTS.txt
64+
```
65+
66+
### Cookies and .env
67+
Now, you will need to get the cookie of your account.
68+
To do so, you can `Ctrl + Shift + I`, go on Network, click on almost any XHR request, and in Request Headers, you should see the raw cookies.
69+
70+
71+
<div style="width: 100%;">
72+
<img src="assets/firefox.png" style="width: 49%">
73+
<img src="assets/chromium.png" style="width: 49%">
74+
</div>
75+
76+
Copy them. This is what authenticate you. So don't share them to anyone else.
77+
78+
After that you copied them, create a `.env` file that follows the same syntax as `template.env` and in `COOKIE`, paste the cookie.
79+
80+
Last thing that you need to do, is to get the ID of your account.
81+
In most request, it's just going to be the first argument of the Payload / Request.
82+
Its in this format: 1234567.
83+
In the .env, the ID should be the ID of your account that you just got.
84+
85+
86+
87+
### Proxy
88+
Now the part about intercepting requests.
89+
If the program can know when the clash is launched, it is thanks to a proxy.
90+
For the interception of requests, the tool used is `mitmproxy`, which as its name indicates, is not necessarily made for that, however, it largely does the job.
91+
You can find more informations on how to install it at
92+
https://mitmproxy.org/
93+
94+
In this program we're going to use the CLI interface with the python API.
95+
96+
97+
For mitmproxy to work, you'll need your browser to listen to the proxy created by mitmproxy.
98+
You can find more information on that here: https://docs.mitmproxy.org/stable/overview-getting-started/
99+
100+
When everything is configured that, as well as the previous steps are done, you can now move on to how to use the program
101+
102+
103+
104+
## Usage
105+
106+
First, you will need to start 2 programs.
107+
- `key.py`. With `python3 key.py`. This program will listen for the key press, and when (r_shit, r_ctrl) are pressed, will automatically (test the code locally, submit it). (Note: if the test in local are all OK and that you are in fastest of reverse, the code will automatically be submitted.)
108+
- `listener.py`. With `mitmproxy -s listener.py`. This will launch a program that will listen to your requests with mitmproxy.
109+
Each time a request comes in, it will execute the `response` function. This function will then see if the response gives any information about the problem.
110+
If it does, then it will get the information about the problem, get the test cases, and open a new window with the problem.
111+

REQUIREMENTS.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
requests
2+
pynput
3+
python-dotenv
4+
ast
5+
mitmproxy
6+
webbrowser
7+
re
8+
json
9+
random

assets/chromium.png

137 KB
Loading

assets/firefox.png

166 KB
Loading

0 commit comments

Comments
 (0)