Skip to content

Commit

Permalink
Some more modifications
Browse files Browse the repository at this point in the history
Now sends data properly to client
  • Loading branch information
Thorinwasher committed Apr 14, 2021
1 parent a6f6dcf commit cd34fb9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pha_bstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
@author: Thorin, Erèsue
"""

import random
import ujson
import os
import threading
import time
Expand Down Expand Up @@ -99,10 +98,11 @@ def create_bstat_dictionary(self):
}
]
}
self.bstats_json = ujson.dumps(self.bstat_dict)
def send_data(self):

url = 'https://bstats.org/submitData/server-implementation'
res = requests.post(url, json=self.bstat_dict)
res = requests.post(url, headers = {'content-type': 'application/json'}, data = self.bstat_dict)
self.logger.debug("Sent message to bstats")
if res.text == "":
pass #TODO idk, some errorprocessing
Expand Down
5 changes: 3 additions & 2 deletions pha_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self,conn,ajson_creator,logger,threadID,addr):
self.client_port = addr[1]

def write_data(self,data):
self.conn.sendall(data)
self.conn.send(data)
def read_data(self,length):
return self.conn.recv(length)

Expand Down Expand Up @@ -97,10 +97,11 @@ def status_connection(self):
self.write_data(self.write_response())
self.logger.debug("Sent JSON response")
elif data == b'':
self.logger.debug("Connection aborted by client")
break
else:
self.write_data(self.pack_varint(len(data)) + data)
self.logger.debug("Responded to ping with:",data)
self.logger.debug("Responded to message with pong")
break

def interpret_login(self):
Expand Down
2 changes: 1 addition & 1 deletion pha_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class json_creator:

def __init__(self,config,logger):
self.Content = config["Content"]
self.Style = config["Style"]
self.Style = int(config["Style"])
self.load_base64()
self.UUIDlist = [
"d2b440c3-edde-4443-899e-6825c31d0919",
Expand Down
2 changes: 1 addition & 1 deletion pha_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def debug(self,*msg):
print(end_msg)

def register_user(self,client_port,client_address,client_username):
msg = "from " + client_address + ":" + str(client_port)
msg = "from " + str(client_address) + ":" + str(client_port)

if client_username is not None:
msg = "Connection as " + client_username.decode("utf8") +" "+ msg
Expand Down
10 changes: 6 additions & 4 deletions phantom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@author: Thorin
"""
import usocket as socket
import socket
from pha_connection import connection_manager
from pha_json import json_creator
from pha_logging import logger
Expand Down Expand Up @@ -45,7 +45,7 @@ def __init__(self):
config_retriever = yaml_manager(defaultConfig,config_path,is_config)
self.config = config_retriever.get_yml()

command_manager().start()
#command_manager().start()

self.is_micropython = config_retriever.is_micropython

Expand All @@ -56,12 +56,14 @@ def __init__(self):
bstats(plugin_id, self.is_micropython,self.logger).start()
self.json_creator = json_creator(self.config,self.logger)
self.host = self.config["serverInfo"]["host"]
self.port = self.config["serverInfo"]["port"]
self.port = int(self.config["serverInfo"]["port"])

def start(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.logger.debug("host:", self.host,"port",self.port)
addr_info = socket.getaddrinfo(self.host,self.port)
try:
s.bind((self.host,self.port))
s.bind(addr_info[0][-1])
i = 1
while True:
s.listen(1)
Expand Down

0 comments on commit cd34fb9

Please sign in to comment.