Porting tgs DMAPI and script updates, as well as getrev updates and something bout OoM.
This commit is contained in:
@@ -1,47 +1,60 @@
|
||||
/world/TgsNew(datum/tgs_event_handler/event_handler)
|
||||
var/tgs_version = world.params[TGS_VERSION_PARAMETER]
|
||||
if(!tgs_version)
|
||||
/world/TgsNew(datum/tgs_event_handler/event_handler, minimum_required_security_level = TGS_SECURITY_ULTRASAFE)
|
||||
var/current_api = TGS_READ_GLOBAL(tgs)
|
||||
if(current_api)
|
||||
TGS_ERROR_LOG("TgsNew(): TGS API datum already set ([current_api])! Was TgsNew() called more than once?")
|
||||
return
|
||||
|
||||
var/path = SelectTgsApi(tgs_version)
|
||||
if(!path)
|
||||
TGS_ERROR_LOG("Found unsupported API version: [tgs_version]. If this is a valid version please report this, backporting is done on demand.")
|
||||
#ifdef TGS_V3_API
|
||||
minimum_required_security_level = TGS_SECURITY_TRUSTED
|
||||
#endif
|
||||
var/raw_parameter = world.params[TGS_VERSION_PARAMETER]
|
||||
if(!raw_parameter)
|
||||
return
|
||||
|
||||
TGS_INFO_LOG("Activating API for version [tgs_version]")
|
||||
var/datum/tgs_api/new_api = new path
|
||||
var/datum/tgs_version/version = new(raw_parameter)
|
||||
if(!version.Valid(FALSE))
|
||||
TGS_ERROR_LOG("Failed to validate TGS version parameter: [raw_parameter]!")
|
||||
return
|
||||
|
||||
var/result = new_api.OnWorldNew(event_handler ? event_handler : new /datum/tgs_event_handler/tgs_default)
|
||||
if(result && result != TGS_UNIMPLEMENTED)
|
||||
TGS_WRITE_GLOBAL(tgs, new_api)
|
||||
else
|
||||
var/api_datum
|
||||
switch(version.suite)
|
||||
if(3)
|
||||
#ifndef TGS_V3_API
|
||||
TGS_ERROR_LOG("Detected V3 API but TGS_V3_API isn't defined!")
|
||||
#else
|
||||
switch(version.major)
|
||||
if(2)
|
||||
api_datum = /datum/tgs_api/v3210
|
||||
#endif
|
||||
if(4)
|
||||
switch(version.major)
|
||||
if(0)
|
||||
api_datum = /datum/tgs_api/v4
|
||||
|
||||
var/datum/tgs_version/max_api_version = TgsMaximumAPIVersion();
|
||||
if(version.suite != null && version.major != null && version.minor != null && version.patch != null && version.deprefixed_parameter > max_api_version.deprefixed_parameter)
|
||||
TGS_ERROR_LOG("Detected unknown API version! Defaulting to latest. Update the DMAPI to fix this problem.")
|
||||
api_datum = /datum/tgs_api/latest
|
||||
|
||||
if(!api_datum)
|
||||
TGS_ERROR_LOG("Found unsupported API version: [raw_parameter]. If this is a valid version please report this, backporting is done on demand.")
|
||||
return
|
||||
|
||||
TGS_INFO_LOG("Activating API for version [version.deprefixed_parameter]")
|
||||
var/datum/tgs_api/new_api = new api_datum(version)
|
||||
|
||||
TGS_WRITE_GLOBAL(tgs, new_api)
|
||||
|
||||
var/result = new_api.OnWorldNew(event_handler, minimum_required_security_level)
|
||||
if(!result || result == TGS_UNIMPLEMENTED)
|
||||
TGS_WRITE_GLOBAL(tgs, null)
|
||||
TGS_ERROR_LOG("Failed to activate API!")
|
||||
|
||||
/world/proc/SelectTgsApi(tgs_version)
|
||||
//remove the old 3.0 header
|
||||
tgs_version = replacetext(tgs_version, "/tg/station 13 Server v", "")
|
||||
|
||||
var/list/version_bits = splittext(tgs_version, ".")
|
||||
|
||||
var/super = text2num(version_bits[1])
|
||||
var/major = text2num(version_bits[2])
|
||||
var/minor = text2num(version_bits[3])
|
||||
var/patch = text2num(version_bits[4])
|
||||
|
||||
switch(super)
|
||||
if(3)
|
||||
switch(major)
|
||||
if(2)
|
||||
return /datum/tgs_api/v3210
|
||||
|
||||
if(super != null && major != null && minor != null && patch != null && tgs_version > TgsMaximumAPIVersion())
|
||||
TGS_ERROR_LOG("Detected unknown API version! Defaulting to latest. Update the DMAPI to fix this problem.")
|
||||
return /datum/tgs_api/latest
|
||||
|
||||
/world/TgsMaximumAPIVersion()
|
||||
return "4.0.0.0"
|
||||
return new /datum/tgs_version("4.0.x.x")
|
||||
|
||||
/world/TgsMinimumAPIVersion()
|
||||
return "3.2.0.0"
|
||||
return new /datum/tgs_version("3.2.0.0")
|
||||
|
||||
/world/TgsInitializationComplete()
|
||||
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
|
||||
@@ -71,7 +84,9 @@
|
||||
return TGS_READ_GLOBAL(tgs) != null
|
||||
|
||||
/world/TgsVersion()
|
||||
return world.params[TGS_VERSION_PARAMETER]
|
||||
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
|
||||
if(api)
|
||||
return api.version
|
||||
|
||||
/world/TgsInstanceName()
|
||||
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
|
||||
@@ -116,6 +131,11 @@
|
||||
if(api)
|
||||
api.ChatPrivateMessage(message, user)
|
||||
|
||||
/world/TgsSecurityLevel()
|
||||
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
|
||||
if(api)
|
||||
api.SecurityLevel()
|
||||
|
||||
/*
|
||||
The MIT License
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
TGS_DEFINE_AND_SET_GLOBAL(tgs, null)
|
||||
|
||||
/datum/tgs_api
|
||||
var/datum/tgs_version/version
|
||||
|
||||
/datum/tgs_api/New(datum/tgs_version/version)
|
||||
. = ..()
|
||||
src.version = version
|
||||
|
||||
/datum/tgs_api/latest
|
||||
parent_type = /datum/tgs_api/v3210
|
||||
parent_type = /datum/tgs_api/v4
|
||||
|
||||
TGS_PROTECT_DATUM(/datum/tgs_api)
|
||||
|
||||
@@ -46,6 +51,9 @@ TGS_PROTECT_DATUM(/datum/tgs_api)
|
||||
/datum/tgs_api/proc/ChatPrivateMessage(message, admin_only)
|
||||
return TGS_UNIMPLEMENTED
|
||||
|
||||
/datum/tgs_api/proc/SecurityLevel()
|
||||
return TGS_UNIMPLEMENTED
|
||||
|
||||
/*
|
||||
The MIT License
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/datum/tgs_event_handler/tgs_default/HandleEvent(event_code)
|
||||
//TODO
|
||||
return
|
||||
|
||||
/*
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2017 Jordan Brown
|
||||
|
||||
Permission is hereby granted, free of charge,
|
||||
to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify,
|
||||
merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom
|
||||
the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,22 @@
|
||||
/datum/tgs_version/New(raw_parameter)
|
||||
src.raw_parameter = raw_parameter
|
||||
deprefixed_parameter = replacetext(raw_parameter, "/tg/station 13 Server v", "")
|
||||
var/list/version_bits = splittext(deprefixed_parameter, ".")
|
||||
|
||||
suite = text2num(version_bits[1])
|
||||
if(version_bits.len > 1)
|
||||
major = text2num(version_bits[2])
|
||||
if(version_bits.len > 2)
|
||||
minor = text2num(version_bits[3])
|
||||
if(version_bits.len == 4)
|
||||
patch = text2num(version_bits[4])
|
||||
|
||||
/datum/tgs_version/proc/Valid(allow_wildcards = FALSE)
|
||||
if(suite == null)
|
||||
return FALSE
|
||||
if(allow_wildcards)
|
||||
return TRUE
|
||||
return !Wildcard()
|
||||
|
||||
/datum/tgs_version/Wildcard()
|
||||
return major == null || minor == null || patch == null
|
||||
Reference in New Issue
Block a user