Skip to content

Commit

Permalink
Merge branch 'master' into nota/grenade-pos-check
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAFile committed Jun 1, 2018
2 parents 2a17795 + 5eac086 commit 4dbee30
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 70 deletions.
1 change: 0 additions & 1 deletion piqueserver/config/config.toml
Expand Up @@ -215,7 +215,6 @@ publish = false
publish_port = 32885

# Bansubscribe allows you to inherit bans from another server with banpublish enabled.
subscribe = false
# urls = [ [ "http://www.blacklist.spadille.net/subscribe.json", []]]


Expand Down
15 changes: 11 additions & 4 deletions piqueserver/core_commands/server.py
@@ -1,5 +1,12 @@
import random

from twisted.logger import Logger

from piqueserver.commands import command, join_arguments

log = Logger()


@command('servername', admin_only=True)
def server_name(connection, *arg):
"""
Expand All @@ -9,13 +16,13 @@ def server_name(connection, *arg):
"""
name = join_arguments(arg)
protocol = connection.protocol
protocol.config['name'] = name
protocol.update_format()
protocol.set_server_name(name)
message = "%s changed servername to '%s'" % (connection.name, name)
print(message)
log.info(message)
connection.protocol.irc_say("* " + message)
if connection in connection.protocol.players:
return message
return None


@command('server')
Expand Down Expand Up @@ -44,7 +51,7 @@ def version(connection):
def scripts(connection):
"""
Tell you which scripts are enabled on this server currently
/version
/scripts
"""
scripts = connection.protocol.config.get('scripts', [])
if len(scripts) > 0:
Expand Down
9 changes: 6 additions & 3 deletions piqueserver/map.py
Expand Up @@ -21,9 +21,12 @@
import random
from typing import List, Optional, Union

from twisted.logger import Logger

from pyspades.vxl import VXLData
from piqueserver.config import config

log = Logger()


class MapNotFound(Exception):
Expand Down Expand Up @@ -65,14 +68,14 @@ def __init__(self, rot_info: 'RotationInfo', load_dir: str) -> None:
if self.gen_script:
seed = rot_info.get_seed()
self.name = '%s #%s' % (rot_info.name, seed)
print("Generating map '%s'..." % self.name)
log.info("Generating map '%s'..." % self.name)
random.seed(seed)
self.data = self.gen_script(rot_info.name, seed)
else:
print("Loading map '%s'..." % self.name)
log.info("Loading map '%s'..." % self.name)
self.load_vxl(rot_info)

print('Map loaded successfully.')
log.info('Map loaded successfully.')

def load_information(self, rot_info: 'RotationInfo', load_dir: str) -> None:
self.load_dir = load_dir
Expand Down
36 changes: 21 additions & 15 deletions piqueserver/player.py
Expand Up @@ -2,6 +2,7 @@
from typing import List, Tuple, Optional, Union

from twisted.internet import reactor
from twisted.logger import Logger

from piqueserver import commands

Expand All @@ -20,6 +21,9 @@

HookValue = Optional[bool]

log = Logger()


class FeatureConnection(ServerConnection):
printable_name = None
admin = False
Expand Down Expand Up @@ -53,8 +57,8 @@ def on_connect(self) -> None:
protocol.remove_ban(client_ip)
protocol.save_bans()
else:
print('banned user %s (%s) attempted to join' % (name,
client_ip))
log.info('banned user %s (%s) attempted to join' % (name,
client_ip))
self.disconnect(ERROR_BANNED)
return

Expand All @@ -63,8 +67,8 @@ def on_connect(self) -> None:
if manager is not None:
reason = manager.get_ban(client_ip)
if reason is not None:
print(('federated banned user (%s) attempted to join, '
'banned for %r') % (client_ip, reason))
log.info(('federated banned user (%s) attempted to join, '
'banned for %r') % (client_ip, reason))
self.disconnect(ERROR_BANNED)
return

Expand All @@ -78,8 +82,9 @@ def on_login(self, name: str) -> None:
self.printable_name = escape_control_codes(name)
if len(self.printable_name) > 15:
self.kick(silent=True)
print('%s (IP %s, ID %s) entered the game!' % (self.printable_name,
self.address[0], self.player_id))
log.info('{name} (IP {ip}, ID {pid}) entered the game!',
name=self.printable_name,
ip=self.address[0], pid=self.player_id)
self.protocol.irc_say('* %s (IP %s, ID %s) entered the game!' %
(self.name, self.address[0], self.player_id))
if self.user_types is None:
Expand All @@ -98,16 +103,17 @@ def get_spawn_location(self) -> Tuple[int, int, int]:

def on_disconnect(self) -> None:
if self.name is not None:
print(self.printable_name, 'disconnected!')
log.info('{name} disconnected!', name=self.printable_name)
self.protocol.irc_say('* %s (IP %s) disconnected' %
(self.name, self.address[0]))
self.protocol.player_memory.append((self.name, self.address[0]))
else:
print('%s disconnected' % self.address[0])
log.info('{ip} disconnected', ip=self.address[0])
ServerConnection.on_disconnect(self)

def on_command(self, command: str, parameters: List[str]) -> None:
result = commands.handle_command(self, command, parameters)
# TODO: Move this logging into command module?
if result == False:
parameters = ['***'] * len(parameters)
log_message = '<%s> /%s %s' % (self.name, command,
Expand All @@ -116,7 +122,7 @@ def on_command(self, command: str, parameters: List[str]) -> None:
log_message += ' -> %s' % result
for i in reversed(result.split("\n")):
self.send_chat(i)
print(escape_control_codes(log_message))
log.info(escape_control_codes(log_message))

def _can_build(self) -> bool:
if not self.can_complete_line_build:
Expand Down Expand Up @@ -152,7 +158,8 @@ def on_secondary_fire_set(self, secondary):
# finds coordinates of the first block this line strikes.
line_start = c.cast_ray()
if line_start: # if player is pointing at a valid point. Distant solid blocks will return False
distance = (Vertex3(*line_start) - Vertex3(position.x, position.y, position.z)).length()
distance = (
Vertex3(*line_start) - Vertex3(position.x, position.y, position.z)).length()
if distance > 6:
self.can_complete_line_build = False
else:
Expand Down Expand Up @@ -352,8 +359,7 @@ def on_chat(self, value: str, global_message: bool) -> Union[str, bool]:
self.chat_count += 1
self.last_chat = current_time

# TODO: replace with logging
print(escape_control_codes(message))
log.info(escape_control_codes(message))

return value

Expand Down Expand Up @@ -392,8 +398,8 @@ def send_lines(self, lines: List[str]) -> None:
current_time += 2

def on_hack_attempt(self, reason):
print('Hack attempt detected from %s: %s' % (self.printable_name,
reason))
log.warn('Hack attempt detected from %s: %s' % (self.printable_name,
reason))
self.kick(reason)

def on_user_login(self, user_type, verbose=True):
Expand All @@ -410,7 +416,7 @@ def on_user_login(self, user_type, verbose=True):

def timed_out(self):
if self.name is not None:
print('%s timed out' % self.printable_name)
log.info('%s timed out' % self.printable_name)
ServerConnection.timed_out(self)


Expand Down

0 comments on commit 4dbee30

Please sign in to comment.