Skip to content

Commit

Permalink
Code drop
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmcwatters committed May 11, 2016
1 parent 610ac21 commit 0e4ae2b
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 1,099 deletions.
28 changes: 10 additions & 18 deletions src/class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ local eventnames = {
local function metamethod( class, eventname )
return function( ... )
local event = nil
local base = nil
if ( class.__base ) then
base = getbaseclass( class )
while ( base ~= nil ) do
if ( base[ eventname ] ) then
event = base[ eventname ]
break
end
base = getbaseclass( base )
local base = getbaseclass( class )
while ( base ~= nil ) do
if ( base[ eventname ] ) then
event = base[ eventname ]
break
end
base = getbaseclass( base )
end
local type = type( event )
if ( type ~= "function" ) then
Expand Down Expand Up @@ -141,15 +138,10 @@ function class( name )
-- our members, metatable, and base class, in that order, a la behavior
-- via the Lua 5.1 manual's illustrative code for indexing access
classes[ name ].__index = function( table, key )
local h
if ( type( table ) == "table" ) then
local v = rawget( table, key )
if ( v ~= nil ) then return v end
v = rawget( classes[ name ], key )
if ( v ~= nil ) then return v end
h = rawget( getbaseclass( classes[ name ] ), "__index" )
if ( h == nil ) then return nil end
end
local v = rawget( classes[ name ], key )
if ( v ~= nil ) then return v end
local h = rawget( getbaseclass( classes[ name ] ), "__index" )
if ( h == nil ) then return nil end
if ( type( h ) == "function" ) then
return h( table, key )
else
Expand Down
36 changes: 0 additions & 36 deletions src/engine/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ require( "engine.client.sound" )
require( "engine.shared.hook" )
require( "engine.shared.network.payload" )

local _AXIS = _AXIS

local bind = bind
local conf = _CONF
local concommand = concommand
Expand Down Expand Up @@ -50,11 +48,6 @@ module( "engine.client" )
function connect( address )
disconnect()

if ( _AXIS and not isSignedIntoAxis() ) then
print( "You are not signed into Axis." )
return
end

require( "engine.client.network" )
network = _G.engine.client.network
_G.networkclient = network
Expand Down Expand Up @@ -302,14 +295,6 @@ function isInGame()
_G.gameclient.playerInitialized
end

if ( _AXIS ) then
function isSignedIntoAxis()
require( "engine.shared.axis" )
local account = _G.axis.getCurrentUser()
return account ~= nil
end
end

function joystickpressed( joystick, button )
gui.joystickpressed( joystick, button )
end
Expand Down Expand Up @@ -391,34 +376,13 @@ function mousereleased( x, y, button, istouch )
bind.mousereleased( x, y, button, istouch )
end

local sendAuthTicket = nil

if ( _AXIS ) then
sendAuthTicket = function( server )
require( "engine.shared.network.payload" )
require( "engine.shared.axis" )

local payload = _G.payload( "authenticate" )
local account = _G.axis.getCurrentUser()
if ( account ) then
payload:set( "ticket", account:getTicket() )
server:send( payload:serialize() )
end
end
end

function onConnect( event )
connecting = false
connected = true
print( "Connected to server!" )

hook.call( "client", "onConnect", tostring( event.peer ) )

if ( _AXIS ) then
local server = event.peer
sendAuthTicket( server )
end

-- Prepare to receive entitySpawned payloads
require( "engine.shared.entities" )
end
Expand Down
135 changes: 1 addition & 134 deletions src/engine/server/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
require( "engine.server.network" )
require( "engine.shared.network.payload" )

local _AXIS = _AXIS

local concommand = concommand
local convar = convar
local debug = debug
Expand Down Expand Up @@ -66,12 +64,6 @@ end

function onConnect( event )
print( tostring( event.peer ) .. " has connected." )

if ( _AXIS ) then
-- Post-connect occurs post-authenticate
return
end

onPostConnect( event )
end

Expand All @@ -96,11 +88,6 @@ function onPostConnect( event )
local player = _G.player.initialize( event.peer )
player:setRegion( _G.region.getByName( region ) )

if ( _AXIS ) then
player:setAuthenticated( true )
getAccount( player, event.peer )
end

player:onConnect()

-- Set spawn point
Expand All @@ -112,20 +99,7 @@ function onPostConnect( event )
player:setNetworkVar( "position", position )

-- Send server info
if ( _AXIS ) then
local account = player:getAccount()
if ( account ) then
local username = account:getUsername()
player:setNetworkVar( "name", username )
print( "Player " .. username .. " has joined the game." )
player:onAuthenticated()
sendServerInfo( player )
else
-- Player disconnected during authentication phase
end
else
sendServerInfo( player )
end
sendServerInfo( player )
end

local directoryWhitelist = {
Expand Down Expand Up @@ -188,81 +162,12 @@ function onDisconnect( event )
local player = _G.player.getByPeer( event.peer )
if ( player ) then
player:onDisconnect()

if ( _AXIS ) then
local account = player:getAccount()
if ( account ) then
local username = account:getUsername()
print( "Player " .. username .. " has left the game." )
end
end

player:remove()
end

print( tostring( event.peer ) .. " has disconnected." )
end

if ( _AXIS ) then
local function onPlayerAuthenticateHandler( payload )
local peer = payload:getPeer()
local ticket = payload:get( "ticket" )
local player = {
peer = peer,
ticket = ticket
}
table.insert( players, player )
onPlayerAuthenticate( peer, ticket )
end

payload.setHandler( onPlayerAuthenticateHandler, "authenticate" )

function onPlayerAuthenticate( peer, ticket )
require( "engine.shared.axis" )
_G.axis.authenticate( ticket, onPostPlayerAuthenticate( peer ) )
end

local function kick( peer, message )
local payload = payload( "kick" )
payload:set( "message", message )
peer:send( payload:serialize() )
peer:disconnect_later()
end

local function setAccount( peer, r )
require( "public.json" )
require( "engine.shared.axis.axisuser" )

local account = _G.json.decode( r )
local username = account.username
local email = account.email
local ticket = account.ticket
local user = _G.axisuser( username, email, ticket )
for _, player in ipairs( players ) do
if ( player.ticket == ticket ) then
player.ticket = nil
player.account = user
end
end
end

function onPostPlayerAuthenticate( peer )
return function( r, c, h, s )
if ( c ~= 200 ) then
kick( peer, "Axis authentication failed!" )
return
end

setAccount( peer, r )

local event = {
peer = peer
}
onPostConnect( event )
end
end
end

local function sendEntities( player )
local entities = _G.entity.getAll()
for _, entity in ipairs( entities ) do
Expand Down Expand Up @@ -322,49 +227,11 @@ function quit()
end

function sendServerInfo( player )
if ( _AXIS ) then
require( "engine.shared.axis" )
local account = player:getAccount()
local username = account:getUsername()
local appSecret = _G.game.appSecret
_G.axis.getSavedGame( username, appSecret, nil, onGetSavedGame( player ) )
return
end

local payload = payload( "serverInfo" )
payload:set( "region", _G.game.initialRegion )
player:send( payload )
end

function onGetSavedGame( player )
return function( r, c, h, s )
-- Server shutdown before operation completed.
if ( not _G.game ) then
return
end

local payload = payload( "serverInfo" )

require( "public.json" )

local save = nil

if ( c == 200 ) then
-- FIXME; Decode twice since we get back escaped save data.
save = _G.json.decode( r )
save = _G.json.decode( save )
elseif ( c == 404 ) then
save = player:createInitialSave()
local r = _G.json.encode( save )
_G.axis.setSavedGame( username, appSecret, nil, r )
end

payload:set( "region", save.region )
payload:set( "save", c == 200 and r or _G.json.encode( save ) )
player:send( payload )
end
end

shutdown = quit

function update( dt )
Expand Down
Loading

0 comments on commit 0e4ae2b

Please sign in to comment.