Dateien hochladen nach „“
parent
d968674011
commit
70b3743226
|
@ -0,0 +1,50 @@
|
|||
import sys
|
||||
from PodSixNet.Connection import connection
|
||||
from PodSixNet.Connection import ConnectionListener
|
||||
import time
|
||||
import threading
|
||||
import os
|
||||
#os.system('cls' if os.name == 'nt' else 'clear')
|
||||
name = input("name: ")
|
||||
queue = []
|
||||
recorded = []
|
||||
temp = 0
|
||||
class MyNetworkListener(ConnectionListener):
|
||||
def __init__(self, host, port):
|
||||
self.Connect((host, port))
|
||||
|
||||
def Network_queuesync(self, data):
|
||||
global temp
|
||||
temp = 0
|
||||
global queue
|
||||
queue = data["queue"]
|
||||
|
||||
connection2 = MyNetworkListener(input("host: "), int(input("port: ")))
|
||||
data = {"action": "setname", "name":name}
|
||||
connection2.Send(data)
|
||||
def chatloop():
|
||||
global connection2
|
||||
global recorded
|
||||
while True:
|
||||
for line in sys.stdin:
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
for i in recorded:
|
||||
print(i)
|
||||
data = {"action": "send", "message": line}
|
||||
connection2.Send(data)
|
||||
threading.Thread(target=chatloop).start()
|
||||
while True:
|
||||
for i in queue:
|
||||
print(i)
|
||||
recorded.append(i)
|
||||
queue.remove(i)
|
||||
connection2.Pump()
|
||||
connection.Pump()
|
||||
if temp >= 100:
|
||||
print("lost connection to server.")
|
||||
exit()
|
||||
exit()
|
||||
temp += 1
|
||||
time.sleep(0.001)
|
||||
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
from PodSixNet.Channel import Channel
|
||||
from PodSixNet.Server import Server
|
||||
import time
|
||||
import sys
|
||||
import threading
|
||||
chatters = {}
|
||||
queue = []
|
||||
banned = []
|
||||
|
||||
def tostring(target):
|
||||
temp = ""
|
||||
for i in range(len(target)):
|
||||
index = i
|
||||
i = target[i]
|
||||
if index != len(target)-1:
|
||||
temp = temp + i + " "
|
||||
else:
|
||||
temp = temp + i
|
||||
return temp
|
||||
|
||||
class clientchannel(Channel):
|
||||
def __init__(self, conn=None, addr=..., server=None, map=None):
|
||||
super().__init__(conn, addr, server, map)
|
||||
self.name = "Unknown"
|
||||
|
||||
def Network_send(self, data):
|
||||
global queue
|
||||
queue.append("{}:{}".format(self.name, data["message"]))
|
||||
|
||||
def Network_setname(self, data):
|
||||
global queue
|
||||
global banned
|
||||
if data["name"] in banned:
|
||||
queue.append("{} is banned, disconnecting".format(data["name"]))
|
||||
self.close()
|
||||
queue.append("{} joined!".format(data["name"]))
|
||||
global chatters
|
||||
chatters[data["name"]] = self
|
||||
self.name = data["name"]
|
||||
|
||||
class server(Server):
|
||||
channelClass = clientchannel
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
Server.__init__(self, *args, **kwargs)
|
||||
|
||||
def Connected(self, channel, addr):
|
||||
global chatters
|
||||
chatters[channel.name] = channel
|
||||
|
||||
gameserver = server(localaddr=("localhost", 2003))
|
||||
def chatloop():
|
||||
global queue
|
||||
global chatters
|
||||
while True:
|
||||
cmd = input()
|
||||
cmd2 = cmd.split()
|
||||
if cmd2[0] == "kick":
|
||||
cmd2.remove(cmd2[0])
|
||||
cmd = tostring(cmd2)
|
||||
queue.append("{} has been kicked".format(cmd))
|
||||
chatters[cmd].close()
|
||||
chatters.pop(cmd)
|
||||
if cmd2[0] == "ban":
|
||||
cmd2.remove(cmd2[0])
|
||||
cmd = tostring(cmd2)
|
||||
queue.append("{} has been banned".format(cmd))
|
||||
chatters[cmd].close()
|
||||
banned.append(cmd)
|
||||
chatters.pop(cmd)
|
||||
threading.Thread(target=chatloop).start()
|
||||
while True:
|
||||
for i in chatters:
|
||||
chatters[i].Send({"action": "queuesync", "queue": queue})
|
||||
for i in queue:
|
||||
print(i)
|
||||
queue.remove(i)
|
||||
gameserver.Pump()
|
||||
time.sleep(0.001)
|
Loading…
Reference in New Issue