Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions launcher/server/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
import random
import socket
import sys
import threading
import time
import traceback
from collections import deque
import socket
import traceback
import threading
import random
from hashlib import sha1


Expand Down Expand Up @@ -62,6 +62,8 @@ def byte(v):
game = None
game_password = 0
launch_timeout = 0
netplay_ntsc = 0
netplay_debug = 0
server_protocol_version = byte(SERVER_PROTOCOL_VERSION)


Expand Down Expand Up @@ -205,7 +207,8 @@ def send_queued_messages(self):
def __send_queued_messages(self):
data = b"".join(self.messages)
self.messages[:] = []
# print("sending", repr(data))
if netplay_debug == 1:
print("sending", repr(data))
self.__send_data(data)

def initialize_client(self):
Expand Down Expand Up @@ -274,7 +277,8 @@ def __thread_function(self):
try:
try:
if not self.initialize_client():
# print("initialize failed for", self)
if netplay_debug == 1:
print("initialize failed for", self)
return
self.receive_loop()
except Exception:
Expand Down Expand Up @@ -485,7 +489,10 @@ def __game_loop(self):

def __game_loop_iteration(self):
# FIXME: higher precision sleep?
target_time = self.time + 0.02
if netplay_ntsc == 1:
target_time = self.time + 1/59.97
else:
target_time = self.time + 1/50
t2 = time.time()
diff = target_time - t2
sleep = diff - 0.001
Expand Down Expand Up @@ -736,7 +743,7 @@ def run_server():


def main():
global port, num_clients, game_password, launch_timeout
global port, num_clients, game_password, launch_timeout,netplay_debug,netplay_ntsc
for arg in sys.argv:
if arg.startswith("--"):
parts = arg[2:].split("=", 1)
Expand All @@ -751,6 +758,13 @@ def main():
# game_password = crc32(value) & 0xffffffff
game_password = create_game_password(value)
# print("game password (numeric) is", game_password)
#ADDED:
elif key == "netplay-debug":
netplay_debug = int(value)
elif key == "netplay-ntsc":
print("Server launching in NTSC mode")
netplay_ntsc = int(value)
#End of adding
elif key == "launch-timeout":
launch_timeout = int(value)
run_server()
Expand Down