Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: BattlefieldRedux/StatsPython
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: startersclan/StatsPython
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 12 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 7, 2022

  1. Fix (python): Fix miniclient.http_get() causing nginx to fail with 499

    `499` happens on `nginx` when the client closes the connection before `nginx` replies. See: https://stackoverflow.com/questions/12973304/possible-reason-for-nginx-499-error-codes
    
    The solution is to close the connection after the response is received from the server.
    leojonathanoh committed Oct 7, 2022
    Copy the full SHA
    308b593 View commit details
  2. Merge pull request #1 from startersclan/fix/python-fix-miniclient.htt…

    …p-get-causing-nginx-to-fail-with-499
    
    Fix (python): Fix miniclient.http_get() causing nginx to fail with `499`
    leojonathanoh authored Oct 7, 2022
    Copy the full SHA
    a99eec5 View commit details
  3. Copy the full SHA
    176de4d View commit details
  4. Merge pull request #2 from startersclan/fix/python-fix-http-library-t…

    …o-support-chunked-responses
    
    Fix (python): Fix http library to support chunked responses
    leojonathanoh authored Oct 7, 2022
    Copy the full SHA
    b21652e View commit details

Commits on Jan 21, 2023

  1. Fix (python): Fix regression in miniclient.http_get() to read full …

    …response body if `Content-Length` or `Transfer-Encoding` HTTP Headers are absent
    
    This fixes a critical regression that causes the BF2 server to not process stats if the ASP webserver does not respond with `Content-Length` or `Transfer-Encoding` HTTP Headers.
    
    Fixes regression in #2.
    leojonathanoh committed Jan 21, 2023
    Copy the full SHA
    deab8a5 View commit details
  2. Merge pull request #3 from startersclan/fix/python-fix-regression-in-…

    …miniclient.http-get-to-read-full-response-body-if-content-length-or-transfer-encoding-http-headers-are-absent
    
    Fix (python): Fix regression in `miniclient.http_get()` to read full response body if `Content-Length` or `Transfer-Encoding` HTTP Headers are absent
    leojonathanoh authored Jan 21, 2023
    Copy the full SHA
    13fd579 View commit details

Commits on Jan 22, 2023

  1. Copy the full SHA
    e66e359 View commit details

Commits on Mar 4, 2023

  1. Merge pull request #4 from startersclan/feature/ci-add-github-workflows

    Feature (ci): Add github workflows
    leojonathanoh authored Mar 4, 2023
    Copy the full SHA
    3a6df8b View commit details
  2. Copy the full SHA
    b3de2f5 View commit details
  3. Merge pull request #5 from startersclan/enhancement/ci-add-change-lab…

    …el-to-release-drafter.yml
    
    Enhancement (ci): Add `change` label to `release-drafter.yml`
    leojonathanoh authored Mar 4, 2023
    Copy the full SHA
    5497f4b View commit details

Commits on Nov 22, 2023

  1. Copy the full SHA
    9ba74a8 View commit details
  2. Merge pull request #6 from startersclan/docs/add-notice-about-moving-…

    …files-to-asp
    
    Docs: Add notice about moving files to ASP
    leojonathanoh authored Nov 22, 2023
    Copy the full SHA
    487d6df View commit details
Showing with 181 additions and 40 deletions.
  1. +49 −0 .github/release-drafter.yml
  2. +38 −0 .github/workflows/ci-master-pr.yml
  3. +10 −0 README.md
  4. +84 −40 stats/miniclient.py
49 changes: 49 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name-template: 'v$RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- 'change'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bug'
- title: '🖊️ Refactors'
labels:
- 'refactor'
- title: '👗 Style'
labels:
- 'style'
- title: '📝 Documentation'
labels:
- 'docs'
- 'documentation'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
version-resolver:
major:
labels:
- 'breaking'
minor:
labels:
- 'feature'
- 'enhancement'
- 'change'
- 'refactor'
patch:
labels:
- 'fix'
- 'bug'
- 'style'
- 'docs'
- 'documentation'
- 'chore'
default: patch
sort-by: title
template: |
## Changes
$CHANGES
38 changes: 38 additions & 0 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ci-master-pr

on:
push:
branches:
- master
tags:
- '**'
pull_request:
branches:
- master

jobs:
update-draft-release:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-draft-release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: true
name: ${{ github.ref_name }} # E.g. 'master' or 'v1.2.3'
tag: ${{ github.ref_name }} # E.g. 'master' or 'v1.2.3'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# StatsPython

[![github-actions](https://github.com/startersclan/StatsPython/workflows/ci-master-pr/badge.svg)](https://github.com/startersclan/StatsPython/actions)
[![github-release](https://img.shields.io/github/v/release/startersclan/StatsPython?style=flat-square)](https://github.com/startersclan/StatsPython/releases/)

BF2Statistics [`3.x.x`](https://github.com/startersclan/ASP) python files for the BF2 server.

## Moved

Note that since `3.3.0`, the python files have been moved to https://github.com/startersclan/ASP.
124 changes: 84 additions & 40 deletions stats/miniclient.py
Original file line number Diff line number Diff line change
@@ -18,40 +18,64 @@ def http_get(host, port = 80, document = "/"):

raise

http.writeline("GET %s HTTP/1.1" % str(document))
http.writeline("Host: %s" % host)
http.writeline("User-Agent: GameSpyHTTP/1.0")
http.writeline("Connection: close") # do not keep-alive
http.writeline("")
http.shutdown() # be nice, tell the http server we're done sending the request

# Determine Status
statusCode = 0
status = string.split(http.readline())
if status[0] != "HTTP/1.1":
print "MiniClient: Unknown status response (%s)" % str(status[0])

try:
statusCode = string.atoi(status[1])
except ValueError:
print "MiniClient: Non-numeric status code (%s)" % str(status[1])

#Extract Headers
headers = []
while 1:
line = http.readline()
if not line:
break
headers.append(line)

http.close() # all done

#Check we got a valid HTTP response
if statusCode == 200:
return http.read()
else:
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))

http.writeline("GET %s HTTP/1.1" % str(document))
http.writeline("Host: %s" % host)
http.writeline("User-Agent: GameSpyHTTP/1.0")
http.writeline("Connection: close") # do not keep-alive
http.writeline("")

# Determine Status
statusCode = 0
status = string.split(http.readline())
if status[0] != "HTTP/1.1":
print "MiniClient: Unknown status response (%s)" % str(status[0])

try:
statusCode = string.atoi(status[1])
except ValueError:
print "MiniClient: Non-numeric status code (%s)" % str(status[1])

#Extract Headers
headers = {}
while 1:
line = http.readline()
if not line:
break
split = line.split(":")
headers[split[0].strip()] = split[1].strip()

#Check we got a valid HTTP response
if statusCode == 200:
body = ""
if "Content-Length" in headers:
content_length = headers["Content-Length"]
body = http.read()
elif "Transfer-Encoding" in headers and headers["Transfer-Encoding"] == "chunked":
while 1:
chunk_length = int(http.readline(), 16)
if chunk_length != 0:
body += http.read(chunk_length)
http.readline() # CRLF
if chunk_length == 0:
break
else:
# No Content-Length nor Transfer-Encoding header. Read until EOF
body = http.read()

http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
return body
else:
http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))

except Exception, e:
http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
raise



def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
@@ -76,7 +100,6 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
http.writeline("")
http.writeline(str(snapshot))
http.writeline("")
http.shutdown() # be nice, tell the http server we're done sending the request

# Check that SnapShot Arrives.
# Determine Status
@@ -91,21 +114,42 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
print "MiniClient: Non-numeric status code (%s)" % str(status[1])

#Extract Headers
headers = []
headers = {}
while 1:
line = http.readline()
if not line:
break
headers.append(line)

http.close() # all done

split = line.split(":")
headers[split[0].strip()] = split[1].strip()

if statusCode == 200:
return http.read()
body = ""
if "Content-Length" in headers:
content_length = headers["Content-Length"]
body = http.read()
elif "Transfer-Encoding" in headers and headers["Transfer-Encoding"] == "chunked":
while 1:
chunk_length = int(http.readline(), 16)
if chunk_length != 0:
body += http.read(chunk_length)
http.readline() # CRLF
if chunk_length == 0:
break
else:
# No Content-Length nor Transfer-Encoding header. Read until EOF
body = http.read()

http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
return body
else:
http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
return "E\nH\terr\nD\tHTTP Error %s \"%s\"\n$\tERR\t$" % (str(statusCode), str(status[2]))

except Exception, e:
http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
raise

class miniclient: