tests: Trim .nim files trailing whitespace
via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
This commit is contained in:
parent
ac9c1cd6b9
commit
e80465dacf
372 changed files with 4486 additions and 4486 deletions
|
|
@ -17,7 +17,7 @@ var
|
|||
## I was high.
|
||||
clients = initTable[TupAddress, PClient](16)
|
||||
alias2client = initTable[string, PClient](32)
|
||||
allClients: seq[PClient] = @[]
|
||||
allClients: seq[PClient] = @[]
|
||||
|
||||
proc findClient*(host: string; port: int16): PClient =
|
||||
let addy: TupAddress = (host, port)
|
||||
|
|
@ -37,7 +37,7 @@ proc loginZone(client: PClient; login: SdZoneLogin): bool =
|
|||
result = true
|
||||
break
|
||||
|
||||
proc sendZoneList(client: PClient) =
|
||||
proc sendZoneList(client: PClient) =
|
||||
echo(">> zonelist ", client, ' ', HZoneList)
|
||||
client.send(HZonelist, zonelist)
|
||||
proc forwardPrivate(rcv: PClient; sender: PClient; txt: string) =
|
||||
|
|
@ -93,7 +93,7 @@ proc sendServMsg(client: PClient; msg: string) =
|
|||
var m = newDsMsg(msg)
|
||||
client.send HDsMsg, m
|
||||
handlers[HZoneLogin] = proc(client: PClient; stream: PStream) =
|
||||
var
|
||||
var
|
||||
login = readSdZoneLogin(stream)
|
||||
if not client.loginZone(login):
|
||||
client.sendServMsg "Invalid login"
|
||||
|
|
@ -110,7 +110,7 @@ handlers[HFileChallenge] = proc(client: PClient; stream: PStream) =
|
|||
var chg = readScFileChallenge(stream)
|
||||
|
||||
proc handlePkt(s: PClient; stream: PStream) =
|
||||
while not stream.atEnd:
|
||||
while not stream.atEnd:
|
||||
var typ = readChar(stream)
|
||||
if not handlers.hasKey(typ):
|
||||
break
|
||||
|
|
@ -128,7 +128,7 @@ var clientIndex = 0
|
|||
var incoming = newIncomingBuffer()
|
||||
proc poll*(timeout: int = 250) =
|
||||
if server.isNil: return
|
||||
var
|
||||
var
|
||||
reads = @[server]
|
||||
writes = @[server]
|
||||
if select(reads, timeout) > 0:
|
||||
|
|
@ -163,7 +163,7 @@ when isMainModule:
|
|||
case kind
|
||||
of cmdShortOption, cmdLongOption:
|
||||
case key
|
||||
of "f", "file":
|
||||
of "f", "file":
|
||||
if existsFile(val):
|
||||
cfgFile = val
|
||||
else:
|
||||
|
|
@ -177,14 +177,14 @@ when isMainModule:
|
|||
zonelist.network = jsonSettings["network"].str
|
||||
for slot in jsonSettings["zones"].items:
|
||||
zoneSlots.add((slot["name"].str, slot["key"].str))
|
||||
|
||||
|
||||
createServer(port)
|
||||
echo("Listening on port ", port, "...")
|
||||
var pubChatTimer = cpuTime() #newClock()
|
||||
const PubChatDelay = 1000/1000
|
||||
while true:
|
||||
poll(15)
|
||||
## TODO sort this type of thing VV into a queue api
|
||||
## TODO sort this type of thing VV into a queue api
|
||||
if cpuTime() - pubChatTimer > PubChatDelay: #.getElapsedTime.asMilliseconds > 100:
|
||||
pubChatTimer -= pubChatDelay
|
||||
if pubChatQueue.getPosition > 0:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import
|
||||
import
|
||||
streams, md5, sockets, unsigned,
|
||||
sg_packets, zlib_helpers, idgen
|
||||
type
|
||||
|
|
@ -54,7 +54,7 @@ proc newClient*(addy: TupAddress): PClient =
|
|||
new(result, free)
|
||||
result.addy = addy
|
||||
result.outputBuf = newStringStream("")
|
||||
result.outputBuf.flushImpl = proc(stream: PStream) =
|
||||
result.outputBuf.flushImpl = proc(stream: PStream) =
|
||||
stream.setPosition 0
|
||||
PStringStream(stream).data.setLen 0
|
||||
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ var
|
|||
## I was high.
|
||||
clients = initTable[TupAddress, PClient](16)
|
||||
alias2client = initTable[string, PClient](32)
|
||||
allClients: seq[PClient] = @[]
|
||||
zonePlayers: seq[PClient] = @[]
|
||||
allClients: seq[PClient] = @[]
|
||||
zonePlayers: seq[PClient] = @[]
|
||||
const
|
||||
PubChatDelay = 100/1000 #100 ms
|
||||
|
||||
import hashes
|
||||
proc hash*(x: uint16): THash {.inline.} =
|
||||
proc hash*(x: uint16): THash {.inline.} =
|
||||
result = int32(x)
|
||||
|
||||
proc findClient*(host: string; port: int16): PClient =
|
||||
|
|
@ -27,7 +27,7 @@ proc findClient*(host: string; port: int16): PClient =
|
|||
allClients.add(result)
|
||||
|
||||
|
||||
proc sendZoneList(client: PClient) =
|
||||
proc sendZoneList(client: PClient) =
|
||||
echo(">> zonelist ", client)
|
||||
#client.send(HZonelist, zonelist)
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ handlers[HZoneQuery] = proc(client: PClient; stream: PStream) =
|
|||
|
||||
handlers[HZoneJoinReq] = proc(client: PClient; stream: PStream) =
|
||||
var req = readCsZoneJoinReq(stream)
|
||||
echo "Join zone request from (",req.session.id,") ", req.session.alias
|
||||
echo "Join zone request from (",req.session.id,") ", req.session.alias
|
||||
if client.auth and client.kind == CPlayer:
|
||||
echo "Client is authenticated, verifying filez"
|
||||
client.startVerifyingFiles()
|
||||
|
|
@ -97,7 +97,7 @@ handlers[HZoneJoinReq] = proc(client: PClient; stream: PStream) =
|
|||
|
||||
|
||||
proc handlePkt(s: PClient; stream: PStream) =
|
||||
while not stream.atEnd:
|
||||
while not stream.atEnd:
|
||||
var typ = readChar(stream)
|
||||
if not handlers.hasKey(typ):
|
||||
break
|
||||
|
|
@ -114,7 +114,7 @@ var clientIndex = 0
|
|||
var incoming = newIncomingBuffer()
|
||||
proc poll*(timeout: int = 250) =
|
||||
if server.isNil: return
|
||||
var
|
||||
var
|
||||
reads = @[server]
|
||||
writes = @[server]
|
||||
if select(reads, timeout) > 0:
|
||||
|
|
@ -148,7 +148,7 @@ when isMainModule:
|
|||
case kind
|
||||
of cmdShortOption, cmdLongOption:
|
||||
case key
|
||||
of "f", "file":
|
||||
of "f", "file":
|
||||
if existsFile(val):
|
||||
zoneCfgFile = val
|
||||
else:
|
||||
|
|
@ -158,45 +158,45 @@ when isMainModule:
|
|||
else:
|
||||
echo("Unknown option: ", key, " ", val)
|
||||
var jsonSettings = parseFile(zoneCfgFile)
|
||||
let
|
||||
let
|
||||
host = jsonSettings["host"].str
|
||||
port = TPort(jsonSettings["port"].num)
|
||||
zoneFile = jsonSettings["settings"].str
|
||||
dirServerInfo = jsonSettings["dirserver"]
|
||||
|
||||
|
||||
var path = getAppDir()/../"data"/zoneFile
|
||||
if not existsFile(path):
|
||||
echo("Zone settings file does not exist: ../data/", zoneFile)
|
||||
echo(path)
|
||||
quit(1)
|
||||
|
||||
|
||||
## Test file
|
||||
block:
|
||||
var
|
||||
var
|
||||
TestFile: FileChallengePair
|
||||
contents = repeat("abcdefghijklmnopqrstuvwxyz", 2)
|
||||
testFile.challenge = newScFileChallenge("foobar.test", FZoneCfg, contents.len.int32)
|
||||
testFile.challenge = newScFileChallenge("foobar.test", FZoneCfg, contents.len.int32)
|
||||
testFile.file = checksumStr(contents)
|
||||
myAssets.add testFile
|
||||
|
||||
|
||||
setCurrentDir getAppDir().parentDir()
|
||||
block:
|
||||
let zonesettings = readFile(path)
|
||||
var
|
||||
var
|
||||
errors: seq[string] = @[]
|
||||
if not loadSettings(zoneSettings, errors):
|
||||
echo("You have errors in your zone settings:")
|
||||
for e in errors: echo("**", e)
|
||||
quit(1)
|
||||
errors.setLen 0
|
||||
|
||||
|
||||
var pair: FileChallengePair
|
||||
pair.challenge.file = zoneFile
|
||||
pair.challenge.assetType = FZoneCfg
|
||||
pair.challenge.fullLen = zoneSettings.len.int32
|
||||
pair.file = checksumStr(zoneSettings)
|
||||
myAssets.add pair
|
||||
|
||||
|
||||
allAssets:
|
||||
if not load(asset):
|
||||
echo "Invalid or missing file ", file
|
||||
|
|
@ -208,10 +208,10 @@ when isMainModule:
|
|||
expandPath(assetType, file)).int32
|
||||
pair.file = asset.contents
|
||||
myAssets.add pair
|
||||
|
||||
|
||||
echo "Zone has ", myAssets.len, " associated assets"
|
||||
|
||||
|
||||
|
||||
|
||||
dirServer = newServerConnection(dirServerInfo[0].str, dirServerInfo[1].num.TPort)
|
||||
dirServer.handlers[HDsMsg] = proc(serv: PServer; stream: PStream) =
|
||||
var m = readDsMsg(stream)
|
||||
|
|
@ -221,18 +221,18 @@ when isMainModule:
|
|||
if loggedIn:
|
||||
dirServerConnected = true
|
||||
dirServer.writePkt HZoneLogin, login
|
||||
|
||||
|
||||
thisZone.name = jsonSettings["name"].str
|
||||
thisZone.desc = jsonSettings["desc"].str
|
||||
thisZone.ip = "localhost"
|
||||
thisZone.port = port
|
||||
var login = newSdZoneLogin(
|
||||
dirServerInfo[2].str, dirServerInfo[3].str,
|
||||
thisZone)
|
||||
thisZone)
|
||||
#echo "MY LOGIN: ", $login
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
createServer(port)
|
||||
echo("Listening on port ", port, "...")
|
||||
var pubChatTimer = cpuTime()#newClock()
|
||||
|
|
@ -240,7 +240,7 @@ when isMainModule:
|
|||
discard dirServer.pollServer(15)
|
||||
poll(15)
|
||||
## TODO sort this type of thing VV into a queue api
|
||||
#let now = cpuTime()
|
||||
#let now = cpuTime()
|
||||
if cpuTime() - pubChatTimer > PubChatDelay: #.getElapsedTime.asMilliseconds > 100:
|
||||
pubChatTimer -= pubChatDelay #.restart()
|
||||
if pubChatQueue.getPosition > 0:
|
||||
|
|
@ -250,5 +250,5 @@ when isMainModule:
|
|||
c.outputBuf.writeData(addr pubChatQueue.data[0], sizePubChat)
|
||||
pubChatQueue.flush()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
import
|
||||
sockets, streams, tables, times, math, strutils, json, os, md5,
|
||||
sfml, sfml_vector, sfml_colors,
|
||||
sockets, streams, tables, times, math, strutils, json, os, md5,
|
||||
sfml, sfml_vector, sfml_colors,
|
||||
streams_enh, input_helpers, zlib_helpers, client_helpers, sg_packets, sg_assets, sg_gui
|
||||
type
|
||||
TClientSettings = object
|
||||
|
|
@ -33,7 +33,7 @@ var
|
|||
downloadProgress: PButton
|
||||
connectionButtons: seq[PButton] #buttons that depend on connection to function
|
||||
|
||||
template dispmessage(m: expr): stmt =
|
||||
template dispmessage(m: expr): stmt =
|
||||
messageArea.add(m)
|
||||
proc connectZone(host: string; port: TPort)
|
||||
proc connectToDirserv()
|
||||
|
|
@ -63,7 +63,7 @@ proc handleChat(serv: PServer; s: PStream) =
|
|||
proc connectToDirserv() =
|
||||
if dirServer.isNil:
|
||||
dirServer = newServerConnection(clientSettings.dirserver.host, clientSettings.dirserver.port)
|
||||
dirServer.handlers[HHello] = proc(serv: PServer; s: PStream) =
|
||||
dirServer.handlers[HHello] = proc(serv: PServer; s: PStream) =
|
||||
let msg = readScHello(s)
|
||||
dispMessage(msg.resp)
|
||||
setConnected(true)
|
||||
|
|
@ -71,7 +71,7 @@ proc connectToDirserv() =
|
|||
mySession = readScLogin(s)
|
||||
##do something here
|
||||
dirServer.handlers[HZonelist] = proc(serv: PServer; s: PStream) =
|
||||
var
|
||||
var
|
||||
info = readScZonelist(s)
|
||||
zones = info.zones
|
||||
if zones.len > 0:
|
||||
|
|
@ -87,11 +87,11 @@ proc connectToDirserv() =
|
|||
var z = zones[i]
|
||||
zonelist.newButton(
|
||||
text = z.name, position = pos,
|
||||
onClick = proc(b: PButton) =
|
||||
onClick = proc(b: PButton) =
|
||||
setActiveZone(i, z))
|
||||
pos.y += 20
|
||||
showZonelist = true
|
||||
dirServer.handlers[HPoing] = proc(serv: PServer; s: PStream) =
|
||||
dirServer.handlers[HPoing] = proc(serv: PServer; s: PStream) =
|
||||
var ping = readPoing(s)
|
||||
dispmessage("Ping: "& $ping.time)
|
||||
ping.time = epochTime().float32
|
||||
|
|
@ -108,19 +108,19 @@ proc zoneListReq() =
|
|||
writePkt HZonelist, pkt
|
||||
|
||||
##key handlers
|
||||
keyClient.registerHandler(MouseMiddle, down, proc() =
|
||||
keyClient.registerHandler(MouseMiddle, down, proc() =
|
||||
gui.setPosition(getMousePos()))
|
||||
|
||||
keyClient.registerHandler(KeyO, down, proc() =
|
||||
keyClient.registerHandler(KeyO, down, proc() =
|
||||
if keyPressed(KeyRShift): echo(repr(outgoing)))
|
||||
keyClient.registerHandler(KeyTab, down, proc() =
|
||||
activeInput = (activeInput + 1) mod 2) #does this work?
|
||||
keyClient.registerHandler(MouseLeft, down, proc() =
|
||||
keyClient.registerHandler(MouseLeft, down, proc() =
|
||||
let p = getMousePos()
|
||||
gui.click(p)
|
||||
if showZonelist: zonelist.click(p))
|
||||
var mptext = newText("", guiFont, 16)
|
||||
keyClient.registerHandler(MouseRight, down, proc() =
|
||||
keyClient.registerHandler(MouseRight, down, proc() =
|
||||
let p = getMousePos()
|
||||
mptext.setPosition(p)
|
||||
mptext.setString("($1,$2)"%[$p.x.int,$p.y.int]))
|
||||
|
|
@ -133,15 +133,15 @@ proc connectZone(host: string, port: TPort) =
|
|||
zone.handlers[HFileChallenge] = handleFileChallenge
|
||||
zone.handlers[HChallengeResult] = handleFileChallengeResult
|
||||
zone.handlers[HFileTransfer] = handleFileTransfer
|
||||
zone.handlers[HChat] = handleChat
|
||||
zone.handlers[HChat] = handleChat
|
||||
else:
|
||||
zone.sock.connect(host, port)
|
||||
var hello = newCsHello()
|
||||
zone.writePkt HHello, hello
|
||||
|
||||
|
||||
|
||||
proc lobbyReady*() =
|
||||
|
||||
proc lobbyReady*() =
|
||||
keyClient.setActive()
|
||||
gui.setActive(u_alias)
|
||||
|
||||
|
|
@ -186,27 +186,27 @@ proc lobbyInit*() =
|
|||
clientSettings.website = s["website"].str
|
||||
zonelist.setPosition(vec2f(200.0, 100.0))
|
||||
connectionButtons = @[]
|
||||
|
||||
|
||||
downloadProgress = gui.newButton(
|
||||
text = "", position = vec2f(10, 130), onClick = nil)
|
||||
text = "", position = vec2f(10, 130), onClick = nil)
|
||||
downloadProgress.bg.setFillColor(color(34, 139, 34))
|
||||
downloadProgress.bg.setSize(vec2f(0, 0))
|
||||
|
||||
|
||||
var pos = vec2f(10, 10)
|
||||
u_alias = gui.newTextEntry(
|
||||
if s.existsKey("alias"): s["alias"].str else: "alias",
|
||||
if s.existsKey("alias"): s["alias"].str else: "alias",
|
||||
pos)
|
||||
pos.y += 20
|
||||
u_passwd = gui.newTextEntry("buzz", pos)
|
||||
pos.y += 20
|
||||
connectionButtons.add(gui.newButton(
|
||||
text = "Login",
|
||||
text = "Login",
|
||||
position = pos,
|
||||
onClick = tryLogin,
|
||||
startEnabled = false))
|
||||
pos.y += 20
|
||||
fpsText.setPosition(pos)
|
||||
|
||||
|
||||
playBtn = gui.newButton(
|
||||
text = "Play",
|
||||
position = vec2f(680.0, 8.0),
|
||||
|
|
@ -227,7 +227,7 @@ proc lobbyInit*() =
|
|||
connectionButtons.add(gui.newButton(
|
||||
text = "Test Chat",
|
||||
position = vec2f(10.0, 110.0),
|
||||
onClick = (proc(b: PButton) =
|
||||
onClick = (proc(b: PButton) =
|
||||
var pkt = newCsChat(text = "ohai")
|
||||
writePkt HChat, pkt),
|
||||
startEnabled = false))
|
||||
|
|
@ -239,15 +239,15 @@ proc lobbyInit*() =
|
|||
gui.newButton(text = "Scrollback + 1", position = vec2f(185, 10), onClick = proc(b: PButton) =
|
||||
messageArea.scrollBack += 1
|
||||
update(messageArea))
|
||||
gui.newButton(text = "Scrollback - 1", position = vec2f(185+160, 10), onClick = proc(b: PButton) =
|
||||
gui.newButton(text = "Scrollback - 1", position = vec2f(185+160, 10), onClick = proc(b: PButton) =
|
||||
messageArea.scrollBack -= 1
|
||||
update(messageArea))
|
||||
gui.newButton(text = "Flood msg area", position = vec2f(185, 30), onClick = proc(b: PButton) =
|
||||
for i in 0.. <30:
|
||||
for i in 0.. <30:
|
||||
dispMessage($i))
|
||||
|
||||
var i = 0
|
||||
proc lobbyUpdate*(dt: float) =
|
||||
proc lobbyUpdate*(dt: float) =
|
||||
#let res = disp.poll()
|
||||
gui.update(dt)
|
||||
i = (i + 1) mod 60
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue