diff -Nru teeworlds-0.6.1+dfsg/.gitignore teeworlds-0.6.2+dfsg/.gitignore --- teeworlds-0.6.1+dfsg/.gitignore 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/.gitignore 2013-05-01 11:47:39.000000000 +0000 @@ -18,5 +18,5 @@ packetgen* teeworlds* teeworlds_srv* -tileset_borderfix* +tileset_border* versionsrv* diff -Nru teeworlds-0.6.1+dfsg/bam.lua teeworlds-0.6.2+dfsg/bam.lua --- teeworlds-0.6.1+dfsg/bam.lua 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/bam.lua 2013-05-01 11:47:39.000000000 +0000 @@ -8,6 +8,8 @@ config = NewConfig() config:Add(OptCCompiler("compiler")) config:Add(OptTestCompileC("stackprotector", "int main(){return 0;}", "-fstack-protector -fstack-protector-all")) +config:Add(OptTestCompileC("minmacosxsdk", "int main(){return 0;}", "-mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk")) +config:Add(OptTestCompileC("macosxppc", "int main(){return 0;}", "-arch ppc")) config:Add(OptLibrary("zlib", "zlib.h", false)) config:Add(SDL.OptFind("sdl", true)) config:Add(FreeType.OptFind("freetype", true)) @@ -113,8 +115,13 @@ server_link_other = {} if family == "windows" then - table.insert(client_depends, CopyToDirectory(".", "other\\freetype\\lib\\freetype.dll")) - table.insert(client_depends, CopyToDirectory(".", "other\\sdl\\vc2005libs\\SDL.dll")) + if platform == "win32" then + table.insert(client_depends, CopyToDirectory(".", "other\\freetype\\lib32\\freetype.dll")) + table.insert(client_depends, CopyToDirectory(".", "other\\sdl\\lib32\\SDL.dll")) + else + table.insert(client_depends, CopyToDirectory(".", "other\\freetype\\lib64\\freetype.dll")) + table.insert(client_depends, CopyToDirectory(".", "other\\sdl\\lib64\\SDL.dll")) + end if config.compiler.driver == "cl" then client_link_other = {ResCompile("other/icons/teeworlds_cl.rc")} @@ -130,6 +137,9 @@ end function build(settings) + -- apply compiler settings + config.compiler:Apply(settings) + --settings.objdir = Path("objs") settings.cc.Output = Intermediate_Output @@ -137,9 +147,16 @@ settings.cc.flags:Add("/wd4244") else settings.cc.flags:Add("-Wall", "-fno-exceptions") - if platform == "macosx" then - settings.cc.flags:Add("-mmacosx-version-min=10.5", "-isysroot /Developer/SDKs/MacOSX10.5.sdk") - settings.link.flags:Add("-mmacosx-version-min=10.5", "-isysroot /Developer/SDKs/MacOSX10.5.sdk") + if family == "windows" then + -- disable visibility attribute support for gcc on windows + settings.cc.defines:Add("NO_VIZ") + elseif platform == "macosx" then + settings.cc.flags:Add("-mmacosx-version-min=10.5") + settings.link.flags:Add("-mmacosx-version-min=10.5") + if config.minmacosxsdk.value == 1 then + settings.cc.flags:Add("-isysroot /Developer/SDKs/MacOSX10.5.sdk") + settings.link.flags:Add("-isysroot /Developer/SDKs/MacOSX10.5.sdk") + end elseif config.stackprotector.value == 1 then settings.cc.flags:Add("-fstack-protector", "-fstack-protector-all") settings.link.flags:Add("-fstack-protector", "-fstack-protector-all") @@ -156,6 +173,11 @@ else settings.link.libs:Add("pthread") end + + if platform == "solaris" then + settings.link.flags:Add("-lsocket") + settings.link.flags:Add("-lnsl") + end elseif family == "windows" then settings.link.libs:Add("gdi32") settings.link.libs:Add("user32") @@ -284,7 +306,7 @@ release_settings.optimize = 1 release_settings.cc.defines:Add("CONF_RELEASE") -if platform == "macosx" and arch == "ia32" then +if platform == "macosx" then debug_settings_ppc = debug_settings:Copy() debug_settings_ppc.config_name = "debug_ppc" debug_settings_ppc.config_ext = "_ppc_d" @@ -299,32 +321,89 @@ release_settings_ppc.link.flags:Add("-arch ppc") release_settings_ppc.cc.defines:Add("CONF_RELEASE") - debug_settings_x86 = debug_settings:Copy() - debug_settings_x86.config_name = "debug_x86" - debug_settings_x86.config_ext = "_x86_d" - debug_settings_x86.cc.flags:Add("-arch i386") - debug_settings_x86.link.flags:Add("-arch i386") - debug_settings_x86.cc.defines:Add("CONF_DEBUG") - - release_settings_x86 = release_settings:Copy() - release_settings_x86.config_name = "release_x86" - release_settings_x86.config_ext = "_x86" - release_settings_x86.cc.flags:Add("-arch i386") - release_settings_x86.link.flags:Add("-arch i386") - release_settings_x86.cc.defines:Add("CONF_RELEASE") - ppc_d = build(debug_settings_ppc) - x86_d = build(debug_settings_x86) ppc_r = build(release_settings_ppc) - x86_r = build(release_settings_x86) - DefaultTarget("game_debug_x86") - PseudoTarget("release", ppc_r, x86_r) - PseudoTarget("debug", ppc_d, x86_d) - PseudoTarget("server_release", "server_release_x86", "server_release_ppc") - PseudoTarget("server_debug", "server_debug_x86", "server_debug_ppc") - PseudoTarget("client_release", "client_release_x86", "client_release_ppc") - PseudoTarget("client_debug", "client_debug_x86", "client_debug_ppc") + if arch == "ia32" or arch == "amd64" then + debug_settings_x86 = debug_settings:Copy() + debug_settings_x86.config_name = "debug_x86" + debug_settings_x86.config_ext = "_x86_d" + debug_settings_x86.cc.flags:Add("-arch i386") + debug_settings_x86.link.flags:Add("-arch i386") + debug_settings_x86.cc.defines:Add("CONF_DEBUG") + + release_settings_x86 = release_settings:Copy() + release_settings_x86.config_name = "release_x86" + release_settings_x86.config_ext = "_x86" + release_settings_x86.cc.flags:Add("-arch i386") + release_settings_x86.link.flags:Add("-arch i386") + release_settings_x86.cc.defines:Add("CONF_RELEASE") + + x86_d = build(debug_settings_x86) + x86_r = build(release_settings_x86) + end + + if arch == "amd64" then + debug_settings_x86_64 = debug_settings:Copy() + debug_settings_x86_64.config_name = "debug_x86_64" + debug_settings_x86_64.config_ext = "_x86_64_d" + debug_settings_x86_64.cc.flags:Add("-arch x86_64") + debug_settings_x86_64.link.flags:Add("-arch x86_64") + debug_settings_x86_64.cc.defines:Add("CONF_DEBUG") + + release_settings_x86_64 = release_settings:Copy() + release_settings_x86_64.config_name = "release_x86_64" + release_settings_x86_64.config_ext = "_x86_64" + release_settings_x86_64.cc.flags:Add("-arch x86_64") + release_settings_x86_64.link.flags:Add("-arch x86_64") + release_settings_x86_64.cc.defines:Add("CONF_RELEASE") + + x86_64_d = build(debug_settings_x86_64) + x86_64_r = build(release_settings_x86_64) + end + + DefaultTarget("game_debug_x86") + + if config.macosxppc.value == 1 then + if arch == "ia32" then + PseudoTarget("release", ppc_r, x86_r) + PseudoTarget("debug", ppc_d, x86_d) + PseudoTarget("server_release", "server_release_ppc", "server_release_x86") + PseudoTarget("server_debug", "server_debug_ppc", "server_debug_x86") + PseudoTarget("client_release", "client_release_ppc", "client_release_x86") + PseudoTarget("client_debug", "client_debug_ppc", "client_debug_x86") + elseif arch == "amd64" then + PseudoTarget("release", ppc_r, x86_r, x86_64_r) + PseudoTarget("debug", ppc_d, x86_d, x86_64_d) + PseudoTarget("server_release", "server_release_ppc", "server_release_x86", "server_release_x86_64") + PseudoTarget("server_debug", "server_debug_ppc", "server_debug_x86", "server_debug_x86_64") + PseudoTarget("client_release", "client_release_ppc", "client_release_x86", "client_release_x86_64") + PseudoTarget("client_debug", "client_debug_ppc", "client_debug_x86", "client_debug_x86_64") + else + PseudoTarget("release", ppc_r) + PseudoTarget("debug", ppc_d) + PseudoTarget("server_release", "server_release_ppc") + PseudoTarget("server_debug", "server_debug_ppc") + PseudoTarget("client_release", "client_release_ppc") + PseudoTarget("client_debug", "client_debug_ppc") + end + else + if arch == "ia32" then + PseudoTarget("release", x86_r) + PseudoTarget("debug", x86_d) + PseudoTarget("server_release", "server_release_x86") + PseudoTarget("server_debug", "server_debug_x86") + PseudoTarget("client_release", "client_release_x86") + PseudoTarget("client_debug", "client_debug_x86") + elseif arch == "amd64" then + PseudoTarget("release", x86_r, x86_64_r) + PseudoTarget("debug", x86_d, x86_64_d) + PseudoTarget("server_release", "server_release_x86", "server_release_x86_64") + PseudoTarget("server_debug", "server_debug_x86", "server_debug_x86_64") + PseudoTarget("client_release", "client_release_x86", "client_release_x86_64") + PseudoTarget("client_debug", "client_debug_x86", "client_debug_x86_64") + end + end else build(debug_settings) build(release_settings) diff -Nru teeworlds-0.6.1+dfsg/configure.lua teeworlds-0.6.2+dfsg/configure.lua --- teeworlds-0.6.1+dfsg/configure.lua 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/configure.lua 2013-05-01 11:47:39.000000000 +0000 @@ -376,6 +376,8 @@ SetDriversCL(settings) elseif option.driver == "gcc" then SetDriversGCC(settings) + elseif option.driver == "clang" then + SetDriversClang(settings) else error(option.driver.." is not a known c/c++ compile driver") end @@ -393,7 +395,7 @@ local printhelp = function(option) local a = "" if option.desc then a = "for "..option.desc end - print("\t"..option.name.."=gcc|cl") + print("\t"..option.name.."=gcc|cl|clang") print("\t\twhat c/c++ compile driver to use"..a) print("\t"..option.name..".c=FILENAME") print("\t\twhat c compiler executable to use"..a) Binary files /tmp/EwHiv83IFD/teeworlds-0.6.1+dfsg/data/audio/sfx_msg-client.wv and /tmp/3VwfFi555i/teeworlds-0.6.2+dfsg/data/audio/sfx_msg-client.wv differ Binary files /tmp/EwHiv83IFD/teeworlds-0.6.1+dfsg/data/audio/sfx_msg-highlight.wv and /tmp/3VwfFi555i/teeworlds-0.6.2+dfsg/data/audio/sfx_msg-highlight.wv differ diff -Nru teeworlds-0.6.1+dfsg/data/fonts/VERSION teeworlds-0.6.2+dfsg/data/fonts/VERSION --- teeworlds-0.6.1+dfsg/data/fonts/VERSION 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/fonts/VERSION 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1 @@ +2.33 diff -Nru teeworlds-0.6.1+dfsg/data/languages/belarusian.txt teeworlds-0.6.2+dfsg/data/languages/belarusian.txt --- teeworlds-0.6.1+dfsg/data/languages/belarusian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/belarusian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/bosnian.txt teeworlds-0.6.2+dfsg/data/languages/bosnian.txt --- teeworlds-0.6.1+dfsg/data/languages/bosnian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/bosnian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/brazilian_portuguese.txt teeworlds-0.6.2+dfsg/data/languages/brazilian_portuguese.txt --- teeworlds-0.6.1+dfsg/data/languages/brazilian_portuguese.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/brazilian_portuguese.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/bulgarian.txt teeworlds-0.6.2+dfsg/data/languages/bulgarian.txt --- teeworlds-0.6.1+dfsg/data/languages/bulgarian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/bulgarian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -672,6 +672,15 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + Spectate previous == diff -Nru teeworlds-0.6.1+dfsg/data/languages/czech.txt teeworlds-0.6.2+dfsg/data/languages/czech.txt --- teeworlds-0.6.1+dfsg/data/languages/czech.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/czech.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/danish.txt teeworlds-0.6.2+dfsg/data/languages/danish.txt --- teeworlds-0.6.1+dfsg/data/languages/danish.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/danish.txt 2013-05-01 11:47:39.000000000 +0000 @@ -145,6 +145,9 @@ Demo details == Demoinformation +Demofile: %s +== Demo fil: %s + Demos == Demoer @@ -388,9 +391,15 @@ Play == Spil +Play background music +== Spil baggrunds musik + Player == Spiller +Player country: +== Spillernes land: + Player options == Spillermuligheder @@ -398,7 +407,7 @@ == Spillere Please balance teams! -== Venligst balancerer hold! +== Balancer venligst holdet! Prev. weapon == Foregående våben @@ -482,7 +491,7 @@ == Resultatliste Screenshot -== Screenshot +== Skærmbillede Server address: == Serveradresse @@ -538,6 +547,12 @@ Spectate == Kig på +Spectate next +== Kig på næste + +Spectate previous +== Kig på forrige + Spectator mode == Tilskuer mode @@ -548,11 +563,14 @@ == Standard spilletype Standard map -== Standard +== Standard map Stop record == Stop optagelse +Strict gametype filter +== Streng spiltype filter + Sudden Death == Sudden Death @@ -596,13 +614,13 @@ == Type: UI Color -== Brugergrænsefladefarve +== Brugergrænseflade farve Unable to delete the demo == Kunne ikke slette demoen Unable to rename the demo -== Kunne omdøbe demoen +== Kunne ikke omdøbe demoen Use sounds == Anvend lydeffekter @@ -657,22 +675,13 @@ ##### needs translation ##### -Demofile: %s -== - -Play background music -== - -Player country: -== - -Spectate next +Game paused == -Spectate previous +Respawn == -Strict gametype filter +Show only chat messages from friends == ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/dutch.txt teeworlds-0.6.2+dfsg/data/languages/dutch.txt --- teeworlds-0.6.1+dfsg/data/languages/dutch.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/dutch.txt 2013-05-01 11:47:39.000000000 +0000 @@ -223,6 +223,9 @@ Game over == Spel afgelopen +Game paused +== Spel gestopt + Game type == Speltype @@ -466,6 +469,9 @@ Reset to defaults == Standaardinstellingen +Respawn +== Respawn + Rifle == Laser @@ -526,6 +532,9 @@ Show name plates == Laat naamplaat zien +Show only chat messages from friends +== Laat alleen chatberichten van vrienden zien + Show only supported == Laat alleen compatibele servers zien @@ -675,5 +684,4 @@ ##### needs translation ##### -##### old translations ##### - +##### old translations ##### \ No newline at end of file diff -Nru teeworlds-0.6.1+dfsg/data/languages/finnish.txt teeworlds-0.6.2+dfsg/data/languages/finnish.txt --- teeworlds-0.6.1+dfsg/data/languages/finnish.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/finnish.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/french.txt teeworlds-0.6.2+dfsg/data/languages/french.txt --- teeworlds-0.6.1+dfsg/data/languages/french.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/french.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/german.txt teeworlds-0.6.2+dfsg/data/languages/german.txt --- teeworlds-0.6.1+dfsg/data/languages/german.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/german.txt 2013-05-01 11:47:39.000000000 +0000 @@ -1,4 +1,3 @@ - ##### translated strings ##### %d Bytes @@ -223,6 +222,9 @@ Game over == Spiel vorbei +Game paused +== Spiel pausiert + Game type == Spieltyp @@ -466,6 +468,9 @@ Reset to defaults == Standardeinstellung +Respawn +== Respawn + Rifle == Laser @@ -526,6 +531,9 @@ Show name plates == Zeige Namen +Show only chat messages from friends +== Nur Chatnachrichten von Freunden zeigen + Show only supported == Zeige nur unterstützte @@ -675,5 +683,4 @@ ##### needs translation ##### -##### old translations ##### - +##### old translations ##### \ No newline at end of file diff -Nru teeworlds-0.6.1+dfsg/data/languages/hungarian.txt teeworlds-0.6.2+dfsg/data/languages/hungarian.txt --- teeworlds-0.6.1+dfsg/data/languages/hungarian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/hungarian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -660,12 +660,21 @@ Demofile: %s == +Game paused +== + Play background music == Player country: == +Respawn +== + +Show only chat messages from friends +== + Spectate next == diff -Nru teeworlds-0.6.1+dfsg/data/languages/index.txt teeworlds-0.6.2+dfsg/data/languages/index.txt --- teeworlds-0.6.1+dfsg/data/languages/index.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/index.txt 2013-05-01 11:47:39.000000000 +0000 @@ -1,4 +1,3 @@ - ##### language indices ##### belarusian @@ -49,6 +48,10 @@ == Italiano == 380 +kyrgyz +== Кыргызча +== 417 + norwegian == Norsk == 578 diff -Nru teeworlds-0.6.1+dfsg/data/languages/italian.txt teeworlds-0.6.2+dfsg/data/languages/italian.txt --- teeworlds-0.6.1+dfsg/data/languages/italian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/italian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,6 +675,15 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations #####  diff -Nru teeworlds-0.6.1+dfsg/data/languages/kyrgyz.txt teeworlds-0.6.2+dfsg/data/languages/kyrgyz.txt --- teeworlds-0.6.1+dfsg/data/languages/kyrgyz.txt 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/kyrgyz.txt 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,686 @@ +##### translated strings ##### + +%d Bytes +== %d байт + +%d of %d servers, %d players +== %d / %d сервер, %d оюнчу + +%d%% loaded +== %d%% жүктөлдү + +%ds left +== %d сек. калды + +%i minute left +== %i минута калды! + +%i minutes left +== %i минута калды! + +%i second left +== %i секунда калды! + +%i seconds left +== %i секунда калды! + +%s wins! +== %s утту! + +-Page %d- +== -Барак %d- + +Abort +== Жокко чыгаруу + +Add +== Кошуу + +Add Friend +== Досту кошуу + +Address +== Дареги + +All +== Баары + +Alpha +== Тунук. + +Always show name plates +== Ат көрнөкчөлөрдү дайыма көрсөтүү + +Are you sure that you want to delete the demo? +== Сиз чын эле демонун өчүрүлүшүн каалайсызбы? + +Are you sure that you want to quit? +== Сиз чын эле оюндан чыгууну каалайсызбы? + +Are you sure that you want to remove the player from your friends list? +== Сиз чын эле бул оюнчуну достор тизмеңизден өчүргүңүз келеби? + +As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server. +== Бул оюндун биринчи жүргүзүлүшү болгону үчүн, төмөн жакка такма атыңызды киргизиңиз. Серверге туташуу алдында ырастоолорду текшериңиз. + +Automatically record demos +== Демону автоматтуу түрдө жаздыруу + +Automatically take game over screenshot +== Оюн натыйжаларын сүрөткө тартуу + +Blue team +== Көктөр + +Blue team wins! +== Көктөр утту! + +Body +== Дене + +Call vote +== Добуш берүү + +Change settings +== Ырастоолорду өзгөртүү + +Chat +== Маек + +Clan +== Кланы + +Client +== Клиент + +Close +== Чыгуу + +Compatible version +== Батышуучу версия + +Connect +== Туташуу + +Connecting to +== Туташтырылууда + +Connection Problems... +== Байланыш көйгөйлөрү... + +Console +== Консоль + +Controls +== Башкаруу + +Count players only +== Оюнчуларды гана саноо + +Country +== Өлкө + +Crc: +== Crc: + +Created: +== Жаратылганы: + +Current +== Кезектегиси + +Current version: %s +== Кезектеги версиясы: %s + +Custom colors +== Өз түстөрүңүз + +Delete +== Өчүрүү + +Delete demo +== Демону өчүрүү + +Demo details +== Демо деталдары + +Demofile: %s +== Демофайлы: %s + +Demos +== Демолор + +Disconnect +== Өчүрүү + +Disconnected +== Өчүрүлдү + +Display Modes +== Көрсөтүү режимдери + +Downloading map +== Карта жүктөөлүүдө + +Draw! +== Тең! + +Dynamic Camera +== Динамикалык камера + +Emoticon +== Эмоциялар + +Enter +== Кирүү + +Error +== Ката + +Error loading demo +== Демону жүктөө учурундагы ката + +FSAA samples +== FSAA сэмплдери + +Favorite +== Тандалма + +Favorites +== Тандалмалар + +Feet +== Бут + +Filter +== Фильтр + +Fire +== Атуу + +Folder +== Папка + +Force vote +== Тездетүү + +Free-View +== Эркин сереп + +Friends +== Достор + +Fullscreen +== Толук экран + +Game +== Оюн + +Game info +== Оюн жөнүндө + +Game over +== Оюн бүттү + +Game type +== Оюн түрү + +Game types: +== Оюн түрү: + +General +== Негизги + +Graphics +== Графика + +Grenade +== Гранатомёт + +Hammer +== Барскан + +Has people playing +== Бош эмес сервер + +High Detail +== Жогорку деталдаштыруу + +Hook +== Илмек + +Host address +== Сервер дареги + +Hue +== Түсү + +Info +== Маалымат + +Internet +== Интернет + +Invalid Demo +== Жарабаган демо + +Join blue +== Көктөргө + +Join game +== Ойноо + +Join red +== Кызылдарга + +Jump +== Секирүү + +Kick player +== Оюнчуну чыгаруу + +LAN +== LAN + +Language +== Тил + +Length: +== Узундугу: + +Lht. +== Ач. түс. + +Loading +== Жүктөлүүдө + +MOTD +== Күндүн билдирүүсү + +Map +== Картасы + +Map: +== Картасы: + +Max Screenshots +== Сүрөттөрдүн жогорку чеги + +Max demos +== Демолордун жогорку чеги + +Maximum ping: +== Пингдин ж. чеги: + +Miscellaneous +== Кошумча + +Mouse sens. +== Чычкан сезгич. + +Move left +== Солго басуу + +Move player to spectators +== Оюнчуну байкоочуларга ташуу + +Move right +== Оңго басуу + +Movement +== Аракет + +Mute when not active +== Активдүү эмес кезде үндү өчүрүү + +Name +== Аты + +Name plates size +== Ат көрнөкчөлөрдүн өлчөмү + +Netversion: +== Версиясы: + +New name: +== Жаңы аты: + +News +== Жаңылыктар + +Next weapon +== Кийин. курал + +Nickname +== Такма атыңыз + +No +== Жок + +No password +== Сырсөзсүз + +No servers found +== Серверлер табылган жок + +No servers match your filter criteria +== Сиздин фильтриңизге жарай турган серверлер жок + +Ok +== ОК + +Open +== Ачуу + +Parent Folder +== Ата-энелик каталог + +Password +== Сырсөзү + +Password incorrect +== Сырсөз + +Ping +== Пинги + +Pistol +== Тапанча + +Play +== Көрүү + +Play background music +== Фон музыкасын ойнотуу + +Player +== Оюнчу + +Player country: +== Өлкөсү: + +Player options +== Оюнчу опциялары + +Players +== Оюнчулар + +Please balance teams! +== Команадаларды баланстаңыз! + +Prev. weapon +== Мурун. курал + +Quality Textures +== Сапаттуу текстуралар + +Quick search: +== Тез издөө: + +Quit +== Чыгуу + +Quit anyway? +== Чыгуу? + +REC %3d:%02d +== ЖАЗДЫРУУ %3d:%02d + +Reason: +== Себеби: + +Record demo +== Демо жаздыруу + +Red team +== Кызылдар + +Red team wins! +== Кызылдар утту! + +Refresh +== Жаңылоо + +Refreshing master servers +== Мастер-серверлер тизмесин жаңылоо + +Remote console +== Алыскы консоль + +Remove +== Өчүрүү + +Remove friend +== Досту өчүрүү + +Rename +== Атын өзгөртүү + +Rename demo +== Демо атын өзгөртүү + +Reset filter +== Фильтрлерди түшүрүү + +Reset to defaults +== Жарыяланбаска түшүрүү + +Rifle +== Бластер + +Round +== Раунду + +Sample rate +== Жыштыгы + +Sat. +== Канык. + +Score +== Упайы + +Score board +== Табло + +Score limit +== Упай чеги + +Scoreboard +== Табло + +Screenshot +== Сүрөт + +Server address: +== Сервер дареги: + +Server details +== Сервер деталдары + +Server filter +== Сервер фильтри + +Server info +== Маалымат + +Server not full +== Сервер толук эмес + +Settings +== Ырастоолор + +Shotgun +== Мылтык + +Show chat +== Маекти көрсөтүү + +Show friends only +== Достор менен гана + +Show ingame HUD +== Оюн ичиндеги HUD'ни көрсөтүү + +Show name plates +== Оюнчулардын аттарын көрсөтүү + +Show only supported +== Колдолгонду гана көрсөтүү + +Size: +== Өлчөмү: + +Skins +== Терилер + +Sound +== Үн + +Sound error +== Үн катасы + +Sound volume +== Үн көлөмү + +Spectate +== Байкоо + +Spectate next +== Кийин. байкоо + +Spectate previous +== Мурун. байкоо + +Spectator mode +== Байкоочу + +Spectators +== Байкоочулар + +Standard gametype +== Стандарттуу оюн түрү + +Standard map +== Стандарттуу карта + +Stop record +== Токтотуу + +Strict gametype filter +== Оюн түрүнүн так фильтри + +Sudden Death +== Тез өлүм + +Switch weapon on pickup +== Көтөрүлгөн куралга которуу + +Team +== Команда + +Team chat +== Команда маеги + +Teeworlds %s is out! Download it at www.teeworlds.com! +== Teeworlds %s чыкты! www.teeworlds.com сайтынан жүктөп алыңыз! + +Texture Compression +== Текстура кысылышы + +The audio device couldn't be initialised. +== Аудио түзмөгүн инициализациялап алууга мүмкүн эмес. + +The server is running a non-standard tuning on a pure game type. +== Бул сервер стандартту эмес ырастоолор менен таза оюн түрүндө иштеп жатат. + +There's an unsaved map in the editor, you might want to save it before you quit the game. +== Редактордо сакталбаган карта бар, аны оюндан чыгаар алдында сактасаңыз болот. + +Time limit +== Убакыт чеги + +Time limit: %d min +== Убакыт чеги: %d мин. + +Try again +== ОК + +Type +== Түрү + +Type: +== Түрү: + +UI Color +== Интерфейс түсү + +Unable to delete the demo +== Демону өчүрүү мүмкүн эмес + +Unable to rename the demo +== Демо атын өзгөртүү мүмкүн эмес + +Use sounds +== Үндөрдү колдонуу + +Use team colors for name plates +== Аттар үчүн команданын түсүн колдонуу + +V-Sync +== Тик синхрондоштуруусу + +Version +== Версиясы + +Version: +== Версиясы: + +Vote command: +== Добуш коммандасы: + +Vote description: +== Добуш баяндамасы: + +Vote no +== Каршы + +Vote yes +== Макул + +Voting +== Добуш берүү + +Warmup +== Даярдануу + +Weapon +== Курал + +Welcome to Teeworlds +== Teeworlds'ко кош келиңиз! + +Yes +== Ооба + +You must restart the game for all settings to take effect. +== Өзгөртүүлөрдү колдонуу үчүн оюнду кайта жүргүзүңүз. + +Your skin +== Териңиз + +no limit +== чексиз + +Game paused +== Оюн бир азга токтотулду + +Respawn +== Кайра жаралуу + +Show only chat messages from friends +== Достордун гана маек билдирүүлөрүн көрсөтүү + +##### needs translation ##### + +##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/norwegian.txt teeworlds-0.6.2+dfsg/data/languages/norwegian.txt --- teeworlds-0.6.1+dfsg/data/languages/norwegian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/norwegian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/polish.txt teeworlds-0.6.2+dfsg/data/languages/polish.txt --- teeworlds-0.6.1+dfsg/data/languages/polish.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/polish.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,6 +675,15 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### utracić swojej pracy! diff -Nru teeworlds-0.6.1+dfsg/data/languages/portuguese.txt teeworlds-0.6.2+dfsg/data/languages/portuguese.txt --- teeworlds-0.6.1+dfsg/data/languages/portuguese.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/portuguese.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/romanian.txt teeworlds-0.6.2+dfsg/data/languages/romanian.txt --- teeworlds-0.6.1+dfsg/data/languages/romanian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/romanian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/russian.txt teeworlds-0.6.2+dfsg/data/languages/russian.txt --- teeworlds-0.6.1+dfsg/data/languages/russian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/russian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -50,7 +50,7 @@ == Прозрачн. Always show name plates -== Всегда показывать ники игроков +== Всегда показывать имена игроков Are you sure that you want to delete the demo? == Вы уверены, что хотите удалить демо? @@ -62,7 +62,7 @@ == Вы уверены, что хотите удалить игрока из друзей? As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server. -== Так как это ваш первый запуск игры, пожалуйста, введите свой ник в поле ниже. Также рекоммендуется проверить настройки игры и поменять некоторые из них перед тем, как начать играть. +== Пожалуйста, введите своё имя. Также рекоммендуется проверить настройки игры и поменять некоторые из них перед тем, как начать играть. Automatically record demos == Автоматически записывать демо @@ -353,7 +353,7 @@ == След. оружие Nickname -== Ник +== Имя No == Нет @@ -524,7 +524,7 @@ == Показывать внутриигровой HUD Show name plates -== Показывать ники игроков +== Показывать имена игроков Show only supported == Показывать только поддерживаемые разрешения экрана @@ -569,7 +569,7 @@ == Стоп Strict gametype filter -== Строгий фильтр режим. +== Строгий фильтр р-мов Sudden Death == Быстрая смерть @@ -626,7 +626,7 @@ == Использовать звуки Use team colors for name plates -== Командные цвета для ников игроков +== Командные цвета для имен игроков V-Sync == Вертикальная синхронизация @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/serbian.txt teeworlds-0.6.2+dfsg/data/languages/serbian.txt --- teeworlds-0.6.1+dfsg/data/languages/serbian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/serbian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -2,19 +2,19 @@ ##### translated strings ##### %d Bytes -== %d Bytes +== %d Bajtova %d of %d servers, %d players == %d od %d server(a), %d igrač(a) %d%% loaded -== Učitano %d%% +== %d%% učitano %ds left == Još %ds %i minute left -== Još %ds +== %i minut preostao %i minutes left == Preostalo: %i min. @@ -26,7 +26,7 @@ == Preostalo: %i sek. %s wins! -== %s je pobijedio! +== %s je pobedio! -Page %d- == -Strana %d- @@ -68,7 +68,7 @@ == Automatski snimi demo Automatically take game over screenshot -== Automatski napravi screenshot +== Automatski snimi screenshot Blue team == Plavi tim @@ -104,7 +104,7 @@ == Konektuj Connecting to -== Konektujem na +== Konektujem se na Connection Problems... == Problemi sa konekcijom... @@ -116,7 +116,7 @@ == Kontrole Count players only -== Izbroj samo igrače +== Broj samo igrače Country == Država @@ -149,7 +149,7 @@ == Demo-snimak: %s Demos -== Demoi +== Demo-i Disconnect == Diskonektuj @@ -167,7 +167,7 @@ == Nerešeno! Dynamic Camera -== Dinamička kamera +== Dinamična kamera Emoticon == Emoticon @@ -197,10 +197,10 @@ == Filter Fire -== Pucanje +== Pucaj Folder -== Direktorijum +== Folder Force vote == Obavezno glasanje @@ -248,7 +248,7 @@ == Visoki detalji Hook -== Lanac +== Kuka Host address == Adresa servera @@ -338,10 +338,10 @@ == Ime Name plates size -== Veličina pozadine za ime +== Veličina pločice za ime Netversion: -== Net-verzija: +== Net verzija: New name: == Novo ime: @@ -368,13 +368,13 @@ == Nijedan server ne odgovara zadatom kriteriju Ok -== OK +== Ok Open == Otvori Parent Folder -== Prethodni direktorijum +== Prethodni folder Password == Lozinka @@ -458,7 +458,7 @@ == Preimenuj Rename demo -== Preimenuj demo-snimak +== Preimenuj demo Reset filter == Poništi filter @@ -467,7 +467,7 @@ == Resetuj podešavanja Rifle -== Laser +== Puška Round == Runda @@ -518,7 +518,7 @@ == Prikaži chat Show friends only -== Prikaži isključivo prijatelje +== Prikaži samo prijatelje Show ingame HUD == Prikaži HUD @@ -548,10 +548,10 @@ == Posmatraj Spectate next -== Posmatraj narednog +== Posmatraj sledećeg Spectate previous -== Posmatraj prethodnog +== Posmatraj prošlog Spectator mode == Posmatrački mod @@ -590,7 +590,7 @@ == Kompresija tekstura The audio device couldn't be initialised. -== Audio-uređaj nije moguće pokrenuti. +== Audio uređaj nije moguće pokrenuti. The server is running a non-standard tuning on a pure game type. == Server sadrži nestandardna podešavanja. @@ -617,13 +617,13 @@ == Boja menija Unable to delete the demo -== Demo-snimak nije moguće obrisati +== Demo nije moguće obrisati Unable to rename the demo -== Demo-snimak nije moguće preimenovati +== Demo nije moguće preimenovati Use sounds -== Aktiviraj zvuk +== Koristi zvuk Use team colors for name plates == Koristi timsku boju u prikazu imena @@ -644,10 +644,10 @@ == Opis glasanja: Vote no -== Ne +== Protiv Vote yes -== Da +== Za Voting == Glasanje @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/slovak.txt teeworlds-0.6.2+dfsg/data/languages/slovak.txt --- teeworlds-0.6.1+dfsg/data/languages/slovak.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/slovak.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/spanish.txt teeworlds-0.6.2+dfsg/data/languages/spanish.txt --- teeworlds-0.6.1+dfsg/data/languages/spanish.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/spanish.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/swedish.txt teeworlds-0.6.2+dfsg/data/languages/swedish.txt --- teeworlds-0.6.1+dfsg/data/languages/swedish.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/swedish.txt 2013-05-01 11:47:39.000000000 +0000 @@ -675,5 +675,14 @@ ##### needs translation ##### +Game paused +== + +Respawn +== + +Show only chat messages from friends +== + ##### old translations ##### diff -Nru teeworlds-0.6.1+dfsg/data/languages/turkish.txt teeworlds-0.6.2+dfsg/data/languages/turkish.txt --- teeworlds-0.6.1+dfsg/data/languages/turkish.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/turkish.txt 2013-05-01 11:47:39.000000000 +0000 @@ -29,7 +29,7 @@ == %s kazandı! -Page %d- -== -Page %d- +== -Sayfa %d- Abort == İptal @@ -47,25 +47,25 @@ == Hepsi Alpha -== Alfa +== Şeffaflık Always show name plates -== İsim etiketlerini herzaman göster +== Oyuncu isimlerini her zaman göster Are you sure that you want to delete the demo? -== Bu demo dosyasını silmek istediğinize eminmisiniz? +== Demo dosyasını silmek istediğinize emin misiniz? Are you sure that you want to quit? -== Çıkmak istediğinize eminmisiniz? +== Çıkmak istediğinize emin misiniz? Are you sure that you want to remove the player from your friends list? == Bu oyuncuyu arkadaş listenizden kaldırmak istediğinize emin misiniz? As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server. -== Oyunu ilk açışınız olduğundan takma adınızı giriniz. Bir oyuna katılmadan evvel ayarlara bakmanız ve isteğinize göre özelleştirmeniz önerilir. +== Oyunu ilk açışınız olduğundan dolayı takma adınızı giriniz. Bir oyuna katılmadan önce ayarları incelemeniz ve isteklerinize göre özelleştirmeniz önerilir. Automatically record demos -== Otomatik olarak demo kaydet +== Demoları otomatik olarak kaydet Automatically take game over screenshot == Otomatik olarak oyun bitişinde ekran görüntüsü al @@ -86,7 +86,7 @@ == Ayarları değiştir Chat -== Chat +== Sohbet Clan == Clan @@ -95,7 +95,7 @@ == İstemci Close -== Kapa +== Kapat Compatible version == Uyumlu versiyon @@ -107,7 +107,7 @@ == Bağlanılıyor Connection Problems... -== Bağlantı Hatası... +== Bağlantı Hataları... Console == Konsol @@ -122,16 +122,16 @@ == Ülke Crc: -== Crc : +== Crc: Created: -== Hazırlandı : +== Yaratıldı: Current == Şimdiki Current version: %s -== Mevcut versyon : %s +== Mevcut versiyon: %s Custom colors == Özel renkler @@ -145,6 +145,9 @@ Demo details == Demo ayrıntıları +Demofile: %s +== Demo dosyası + Demos == Demolar @@ -164,7 +167,7 @@ == Berabere! Dynamic Camera -== Dinamik kamera +== Dinamik Kamera Emoticon == Yüz ifadesi @@ -224,7 +227,7 @@ == Oyun türü Game types: -== Oyun türü: +== Oyun türleri: General == Genel @@ -239,7 +242,7 @@ == Çekiç Has people playing -== Oynayan insan bulunduran +== Insan bulunduran High Detail == High Detail @@ -302,10 +305,10 @@ == Harita: Max Screenshots -== Maksimum Ekran Alıntısı +== Maksimum Ekran Alıntısı Sayısı Max demos -== Maksimum Demo +== Maksimum Demo Sayısı Maximum ping: == Maximum ping @@ -365,7 +368,7 @@ == Filtre kriterlerinize uygun sunucu bulunamadı Ok -== Ok +== Tamam Open == Aç @@ -388,6 +391,9 @@ Play == Oynat +Play background music +== Arkaplan müziğini çal + Player == Oyuncu @@ -410,7 +416,7 @@ == Hızlı Arama : Quit -== Çıkmak +== Çıkış Quit anyway? == Çıkmak istediğinize emin misiniz? @@ -455,13 +461,13 @@ == Filitreleri varsayılanlara getir Reset to defaults -== Réinitialiser +== Varsayılanlara getir Rifle -== Laser +== Lazer Round -== Round +== Raund Sample rate == Sample rate @@ -515,7 +521,7 @@ == Oyun içi HUD ı göster Show name plates -== İsim etiketlerini göster +== Oyuncu isimlerini göster Show only supported == Desteklenmeyen çözünürlükleri gizle @@ -538,6 +544,12 @@ Spectate == İzle +Spectate next +== Sıradakini izle + +Spectate previous +== Öncekini izle + Spectator mode == İzleyici modu @@ -553,6 +565,9 @@ Stop record == Kaydı durdur +Strict gametype filter +== Sıkı oyun türü filtresi + Sudden Death == Ani ölüm @@ -578,7 +593,7 @@ == Bu sunucu standart olmayan bir ayarı saf bir oyun türünde kullanıyor. There's an unsaved map in the editor, you might want to save it before you quit the game. -== Editörde kaydedilmemiş bir harita var, kapatmadan evvel kaydetmek isteyebilirsiniz. +== Editörde kaydedilmemiş bir harita var, kapatmadan önce kaydetmek isteyebilirsiniz. Time limit == Süre limiti @@ -614,7 +629,7 @@ == V-Sync Version -== Versyon +== Sürüm Version: == Versyon : @@ -626,10 +641,10 @@ == Açıklama : Vote no -== Hayır oyu ver +== Olumsuz oy ver Vote yes -== Evet oyu ver +== Olumlu oy ver Voting == Oylama @@ -641,7 +656,7 @@ == Silah Welcome to Teeworlds -== Teeworlds'e hoşgeldin +== Teeworlds'e hoşgeldiniz Yes == Evet @@ -650,30 +665,27 @@ == Bütün ayarların aktif olması için oyunu yeniden başlatmalısınız. Your skin -== Your skin +== Sizin görünüşünüz no limit == limit yok ##### needs translation ##### -Demofile: %s -== - -Play background music +Game paused == Player country: == -Spectate next -== - -Spectate previous +Respawn == -Strict gametype filter +Show only chat messages from friends == ##### old translations ##### + +== ## translated strings ##### + diff -Nru teeworlds-0.6.1+dfsg/data/languages/ukrainian.txt teeworlds-0.6.2+dfsg/data/languages/ukrainian.txt --- teeworlds-0.6.1+dfsg/data/languages/ukrainian.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/data/languages/ukrainian.txt 2013-05-01 11:47:39.000000000 +0000 @@ -558,6 +558,9 @@ Friends == +Game paused +== + Kick player == @@ -615,6 +618,9 @@ Rename demo == +Respawn +== + Server address: == @@ -627,6 +633,9 @@ Show ingame HUD == +Show only chat messages from friends +== + Size: == diff -Nru teeworlds-0.6.1+dfsg/datasrc/content.py teeworlds-0.6.2+dfsg/datasrc/content.py --- teeworlds-0.6.1+dfsg/datasrc/content.py 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/datasrc/content.py 2013-05-01 11:47:39.000000000 +0000 @@ -471,7 +471,7 @@ weapon.ammoregentime.Set(500) weapon.visual_size.Set(64) weapon.offsetx.Set(32) -weapon.offsety.Set(-4) +weapon.offsety.Set(4) weapon.muzzleoffsetx.Set(50) weapon.muzzleoffsety.Set(6) container.weapons.gun.base.Set(weapon) diff -Nru teeworlds-0.6.1+dfsg/datasrc/network.py teeworlds-0.6.2+dfsg/datasrc/network.py --- teeworlds-0.6.1+dfsg/datasrc/network.py 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/datasrc/network.py 2013-05-01 11:47:39.000000000 +0000 @@ -231,7 +231,7 @@ NetMessage("Sv_Chat", [ NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'), NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'), - NetString("m_pMessage"), + NetStringStrict("m_pMessage"), ]), NetMessage("Sv_KillMsg", [ @@ -294,7 +294,7 @@ ### Client messages NetMessage("Cl_Say", [ NetBool("m_Team"), - NetString("m_pMessage"), + NetStringStrict("m_pMessage"), ]), NetMessage("Cl_SetTeam", [ diff -Nru teeworlds-0.6.1+dfsg/debian/changelog teeworlds-0.6.2+dfsg/debian/changelog --- teeworlds-0.6.1+dfsg/debian/changelog 2011-08-05 13:02:54.000000000 +0000 +++ teeworlds-0.6.2+dfsg/debian/changelog 2013-05-05 07:49:38.000000000 +0000 @@ -1,3 +1,14 @@ +teeworlds (0.6.2+dfsg-1) unstable; urgency=low + + * New upstream release. + - Update patches. + * Pass $CPPFLAGS to the build system. + * Switch to my @debian.org email address. + * Bump Standards-Version to 3.9.4, no changes needed. + * Change Vcs host to anonscm.debian.org. + + -- Felix Geyer Sun, 05 May 2013 09:49:34 +0200 + teeworlds (0.6.1+dfsg-1) unstable; urgency=low * New upstream release. diff -Nru teeworlds-0.6.1+dfsg/debian/control teeworlds-0.6.2+dfsg/debian/control --- teeworlds-0.6.1+dfsg/debian/control 2011-08-04 12:30:23.000000000 +0000 +++ teeworlds-0.6.2+dfsg/debian/control 2013-05-04 13:22:57.000000000 +0000 @@ -2,7 +2,7 @@ Section: games Priority: optional Maintainer: Debian Games Team -Uploaders: Jack Coulter , Felix Geyer +Uploaders: Jack Coulter , Felix Geyer Build-Depends: debhelper (>= 8), bam (>= 0.4), icoutils, @@ -16,10 +16,10 @@ libwavpack-dev, libx11-dev, zlib1g-dev -Standards-Version: 3.9.2 +Standards-Version: 3.9.4 Homepage: http://www.teeworlds.com/ -Vcs-Git: git://git.debian.org/pkg-games/teeworlds.git -Vcs-Browser: http://git.debian.org/?p=pkg-games/teeworlds.git +Vcs-Git: git://anonscm.debian.org/pkg-games/teeworlds.git +Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-games/teeworlds.git Package: teeworlds Architecture: any diff -Nru teeworlds-0.6.1+dfsg/debian/patches/new-wavpack.patch teeworlds-0.6.2+dfsg/debian/patches/new-wavpack.patch --- teeworlds-0.6.1+dfsg/debian/patches/new-wavpack.patch 2011-08-04 12:30:23.000000000 +0000 +++ teeworlds-0.6.2+dfsg/debian/patches/new-wavpack.patch 2013-05-04 13:07:27.000000000 +0000 @@ -1,7 +1,6 @@ -diff -Nur teeworlds-0.6.0.orig/src/engine/client/sound.cpp teeworlds-0.6.0/src/engine/client/sound.cpp ---- teeworlds-0.6.0.orig/src/engine/client/sound.cpp 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/src/engine/client/sound.cpp 2011-05-09 13:46:50.503228772 +0200 -@@ -305,17 +305,14 @@ +--- a/src/engine/client/sound.cpp ++++ b/src/engine/client/sound.cpp +@@ -328,17 +328,14 @@ void CSound::RateConvert(int SampleID) pSample->m_NumFrames = NumFrames; } @@ -18,10 +17,10 @@ WavpackContext *pContext; + char aWholePath[1024]; + IOHANDLE File; - + // don't waste memory on sound when we are stress testing if(g_Config.m_DbgStress) -@@ -328,19 +325,23 @@ +@@ -351,19 +348,23 @@ int CSound::LoadWV(const char *pFilename if(!m_pStorage) return -1; @@ -48,7 +47,7 @@ if (pContext) { int m_aSamples = WavpackGetNumSamples(pContext); -@@ -395,9 +396,6 @@ +@@ -419,9 +420,6 @@ int CSound::LoadWV(const char *pFilename dbg_msg("sound/wv", "failed to open %s: %s", pFilename, aError); } @@ -58,7 +57,7 @@ if(g_Config.m_Debug) dbg_msg("sound/wv", "loaded %s", pFilename); -@@ -482,7 +480,5 @@ +@@ -527,7 +525,5 @@ void CSound::StopAll() lock_release(m_SoundLock); } @@ -66,10 +65,9 @@ - IEngineSound *CreateEngineSound() { return new CSound; } -diff -Nur teeworlds-0.6.0.orig/src/engine/client/sound.h teeworlds-0.6.0/src/engine/client/sound.h ---- teeworlds-0.6.0.orig/src/engine/client/sound.h 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/src/engine/client/sound.h 2011-05-09 13:36:49.520299304 +0200 -@@ -19,10 +19,6 @@ +--- a/src/engine/client/sound.h ++++ b/src/engine/client/sound.h +@@ -21,10 +21,6 @@ public: static void RateConvert(int SampleID); diff -Nru teeworlds-0.6.1+dfsg/debian/patches/pass-build-flags.patch teeworlds-0.6.2+dfsg/debian/patches/pass-build-flags.patch --- teeworlds-0.6.1+dfsg/debian/patches/pass-build-flags.patch 2011-08-04 12:30:23.000000000 +0000 +++ teeworlds-0.6.2+dfsg/debian/patches/pass-build-flags.patch 2013-05-04 13:07:27.000000000 +0000 @@ -1,12 +1,11 @@ -diff -Nur teeworlds-0.6.0.orig/bam.lua teeworlds-0.6.0/bam.lua ---- teeworlds-0.6.0.orig/bam.lua 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/bam.lua 2011-05-09 11:20:20.921209965 +0200 -@@ -284,6 +284,8 @@ +--- a/bam.lua ++++ b/bam.lua +@@ -328,6 +328,8 @@ release_settings.debug = 0 release_settings.optimize = 1 release_settings.cc.defines:Add("CONF_RELEASE") +Import("debian.lua") + - if platform == "macosx" and arch == "ia32" then + if platform == "macosx" then debug_settings_ppc = debug_settings:Copy() debug_settings_ppc.config_name = "debug_ppc" diff -Nru teeworlds-0.6.1+dfsg/debian/patches/set-data-dir.patch teeworlds-0.6.2+dfsg/debian/patches/set-data-dir.patch --- teeworlds-0.6.1+dfsg/debian/patches/set-data-dir.patch 2011-08-04 12:30:23.000000000 +0000 +++ teeworlds-0.6.2+dfsg/debian/patches/set-data-dir.patch 2013-05-04 13:07:27.000000000 +0000 @@ -1,6 +1,5 @@ -diff -Nur teeworlds-0.6.0.orig/src/engine/shared/storage.cpp teeworlds-0.6.0/src/engine/shared/storage.cpp ---- teeworlds-0.6.0.orig/src/engine/shared/storage.cpp 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/src/engine/shared/storage.cpp 2011-05-09 11:22:09.381711049 +0200 +--- a/src/engine/shared/storage.cpp ++++ b/src/engine/shared/storage.cpp @@ -5,7 +5,7 @@ #include "linereader.h" diff -Nru teeworlds-0.6.1+dfsg/debian/patches/system-libs.patch teeworlds-0.6.2+dfsg/debian/patches/system-libs.patch --- teeworlds-0.6.1+dfsg/debian/patches/system-libs.patch 2011-08-04 12:30:23.000000000 +0000 +++ teeworlds-0.6.2+dfsg/debian/patches/system-libs.patch 2013-05-04 13:18:25.000000000 +0000 @@ -1,7 +1,6 @@ -diff -Nur teeworlds-0.6.0.orig/bam.lua teeworlds-0.6.0/bam.lua ---- teeworlds-0.6.0.orig/bam.lua 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/bam.lua 2011-05-09 12:07:26.984318771 +0200 -@@ -11,6 +11,8 @@ +--- a/bam.lua ++++ b/bam.lua +@@ -13,6 +13,8 @@ config:Add(OptTestCompileC("macosxppc", config:Add(OptLibrary("zlib", "zlib.h", false)) config:Add(SDL.OptFind("sdl", true)) config:Add(FreeType.OptFind("freetype", true)) @@ -10,7 +9,7 @@ config:Finalize("config.lua") -- data compiler -@@ -165,7 +167,7 @@ +@@ -187,7 +189,7 @@ function build(settings) end -- compile zlib if needed @@ -19,7 +18,7 @@ settings.link.libs:Add("z") if config.zlib.include_path then settings.cc.includes:Add(config.zlib.include_path) -@@ -176,9 +178,29 @@ +@@ -198,9 +200,29 @@ function build(settings) settings.cc.includes:Add("src/engine/external/zlib") end @@ -52,11 +51,10 @@ -- build game components engine_settings = settings:Copy() -diff -Nur teeworlds-0.6.0.orig/src/engine/client/graphics.cpp teeworlds-0.6.0/src/engine/client/graphics.cpp ---- teeworlds-0.6.0.orig/src/engine/client/graphics.cpp 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/src/engine/client/graphics.cpp 2011-05-09 12:07:13.354255984 +0200 -@@ -20,7 +20,7 @@ - #endif +--- a/src/engine/client/graphics.cpp ++++ b/src/engine/client/graphics.cpp +@@ -9,7 +9,7 @@ + #include "SDL_opengl.h" #include -#include @@ -64,10 +62,9 @@ #include #include -diff -Nur teeworlds-0.6.0.orig/src/engine/client/sound.cpp teeworlds-0.6.0/src/engine/client/sound.cpp ---- teeworlds-0.6.0.orig/src/engine/client/sound.cpp 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/src/engine/client/sound.cpp 2011-05-09 12:07:13.354255984 +0200 -@@ -10,7 +10,7 @@ +--- a/src/engine/client/sound.cpp ++++ b/src/engine/client/sound.cpp +@@ -13,7 +13,7 @@ #include "sound.h" extern "C" { // wavpack @@ -76,9 +73,8 @@ } #include -diff -Nur teeworlds-0.6.0.orig/src/tools/dilate.cpp teeworlds-0.6.0/src/tools/dilate.cpp ---- teeworlds-0.6.0.orig/src/tools/dilate.cpp 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/src/tools/dilate.cpp 2011-05-09 12:07:13.354255984 +0200 +--- a/src/tools/dilate.cpp ++++ b/src/tools/dilate.cpp @@ -2,7 +2,7 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include @@ -88,9 +84,8 @@ typedef struct { -diff -Nur teeworlds-0.6.0.orig/src/tools/tileset_borderfix.cpp teeworlds-0.6.0/src/tools/tileset_borderfix.cpp ---- teeworlds-0.6.0.orig/src/tools/tileset_borderfix.cpp 2011-04-09 21:15:25.000000000 +0200 -+++ teeworlds-0.6.0/src/tools/tileset_borderfix.cpp 2011-05-09 12:07:13.354255984 +0200 +--- a/src/tools/tileset_borderfix.cpp ++++ b/src/tools/tileset_borderfix.cpp @@ -1,7 +1,7 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ @@ -100,3 +95,47 @@ typedef struct { +--- a/src/tools/tileset_borderset.cpp ++++ b/src/tools/tileset_borderset.cpp +@@ -2,7 +2,7 @@ + /* If you are missing that file, acquire a complete release at teeworlds.com. */ + #include + #include +-#include ++#include + + typedef struct + { +--- a/src/engine/client/graphics_threaded.cpp ++++ b/src/engine/client/graphics_threaded.cpp +@@ -6,7 +6,7 @@ + #include + + #include +-#include ++#include + + #include + #include +--- a/src/tools/tileset_borderadd.cpp ++++ b/src/tools/tileset_borderadd.cpp +@@ -2,7 +2,7 @@ + /* If you are missing that file, acquire a complete release at teeworlds.com. */ + #include + #include +-#include ++#include + + typedef struct + { +--- a/src/tools/tileset_borderrem.cpp ++++ b/src/tools/tileset_borderrem.cpp +@@ -2,7 +2,7 @@ + /* If you are missing that file, acquire a complete release at teeworlds.com. */ + #include + #include +-#include ++#include + + typedef struct + { diff -Nru teeworlds-0.6.1+dfsg/debian/rules teeworlds-0.6.2+dfsg/debian/rules --- teeworlds-0.6.1+dfsg/debian/rules 2011-08-05 09:42:16.000000000 +0000 +++ teeworlds-0.6.2+dfsg/debian/rules 2013-05-04 12:57:08.000000000 +0000 @@ -2,6 +2,7 @@ # -*- makefile -*- CFLAGS := $(shell dpkg-buildflags --get CFLAGS) +CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS) LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed upstreamversion := $(shell dpkg-parsechangelog | sed -n 's/^Version: *\([^-]\+\)-.\+/\1/p') @@ -11,7 +12,7 @@ override_dh_auto_build: echo "release_settings.optimize = 0" >> debian.lua - echo "release_settings.cc.flags:Add(\"$(CFLAGS)\")" >> debian.lua + echo "release_settings.cc.flags:Add(\"$(CFLAGS) $(CPPFLAGS)\")" >> debian.lua echo "release_settings.link.inputflags = release_settings.link.inputflags .. \" $(LDFLAGS)\"" >> debian.lua bam -a -v release @@ -49,14 +50,16 @@ dfsg-free: rm -r docs/tool rm -r other/freetype/include - rm -r other/freetype/lib + rm -r other/freetype/lib32 + rm -r other/freetype/lib64 rm -r other/sdl/include - rm -r other/sdl/vc*libs + rm -r other/sdl/lib32 + rm -r other/sdl/lib64 rm -r src/engine/external rm data/fonts/DejaVuSans.ttf rm data/fonts/LICENSE - cd ..; mv $(CURDIR) teeworlds-$(upstreamversion)-dfsg; \ + cd ..; mv $(CURDIR) teeworlds-$(upstreamversion); \ tar --exclude debian \ - -czf teeworlds_$(upstreamversion)+dfsg.orig.tar.gz \ - teeworlds-$(upstreamversion)-dfsg + -czf teeworlds_$(upstreamversion).orig.tar.gz \ + teeworlds-$(upstreamversion) diff -Nru teeworlds-0.6.1+dfsg/license.txt teeworlds-0.6.2+dfsg/license.txt --- teeworlds-0.6.1+dfsg/license.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/license.txt 2013-05-01 11:47:39.000000000 +0000 @@ -1,4 +1,4 @@ -Copyright (C) 2007-2011 Magnus Auvinen +Copyright (C) 2007-2012 Magnus Auvinen This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -25,4 +25,4 @@ ------------------------------------------------------------------------ With that being said, contact us if there is anything you want to do -that the license does not premit. +that the license does not permit. diff -Nru teeworlds-0.6.1+dfsg/other/freetype/VERSION teeworlds-0.6.2+dfsg/other/freetype/VERSION --- teeworlds-0.6.1+dfsg/other/freetype/VERSION 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/other/freetype/VERSION 2013-05-01 11:47:39.000000000 +0000 @@ -1 +1 @@ -2.4.4 +2.4.8 diff -Nru teeworlds-0.6.1+dfsg/other/freetype/freetype.lua teeworlds-0.6.2+dfsg/other/freetype/freetype.lua --- teeworlds-0.6.1+dfsg/other/freetype/freetype.lua 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/other/freetype/freetype.lua 2013-05-01 11:47:39.000000000 +0000 @@ -5,7 +5,7 @@ local check = function(option, settings) option.value = false option.use_ftconfig = false - option.use_win32lib = false + option.use_winlib = 0 option.lib_path = nil if ExecuteSilent("freetype-config") > 0 and ExecuteSilent("freetype-config --cflags") == 0 then @@ -15,7 +15,10 @@ if platform == "win32" then option.value = true - option.use_win32lib = true + option.use_winlib = 32 + elseif platform == "win64" then + option.value = true + option.use_winlib = 64 end end @@ -27,8 +30,12 @@ settings.cc.flags:Add("`freetype-config --cflags`") settings.link.flags:Add("`freetype-config --libs`") - elseif option.use_win32lib == true then - settings.link.libpath:Add(FreeType.basepath .. "/lib") + elseif option.use_winlib > 0 then + if option.use_winlib == 32 then + settings.link.libpath:Add(FreeType.basepath .. "/lib32") + else + settings.link.libpath:Add(FreeType.basepath .. "/lib64") + end settings.link.libs:Add("freetype") end end @@ -36,13 +43,14 @@ local save = function(option, output) output:option(option, "value") output:option(option, "use_ftconfig") - output:option(option, "use_win32lib") + output:option(option, "use_winlib") end local display = function(option) if option.value == true then if option.use_ftconfig == true then return "using freetype-config" end - if option.use_win32lib == true then return "using supplied win32 libraries" end + if option.use_winlib == 32 then return "using supplied win32 libraries" end + if option.use_winlib == 64 then return "using supplied win64 libraries" end return "using unknown method" else if option.required then diff -Nru teeworlds-0.6.1+dfsg/other/sdl/sdl.lua teeworlds-0.6.2+dfsg/other/sdl/sdl.lua --- teeworlds-0.6.1+dfsg/other/sdl/sdl.lua 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/other/sdl/sdl.lua 2013-05-01 11:47:39.000000000 +0000 @@ -5,7 +5,7 @@ local check = function(option, settings) option.value = false option.use_sdlconfig = false - option.use_win32sdl = false + option.use_winlib = 0 option.use_osxframework = false option.lib_path = nil @@ -16,7 +16,10 @@ if platform == "win32" then option.value = true - option.use_win32sdl = true + option.use_winlib = 32 + elseif platform == "win64" then + option.value = true + option.use_winlib = 64 end if platform == "macosx" then @@ -37,9 +40,13 @@ client_settings.cc.includes:Add("/Library/Frameworks/SDL.framework/Headers") end - if option.use_win32sdl == true then + if option.use_winlib > 0 then settings.cc.includes:Add(SDL.basepath .. "/include") - settings.link.libpath:Add(SDL.basepath .. "/vc2005libs") + if option.use_winlib == 32 then + settings.link.libpath:Add(SDL.basepath .. "/lib32") + else + settings.link.libpath:Add(SDL.basepath .. "/lib64") + end settings.link.libs:Add("SDL") settings.link.libs:Add("SDLmain") end @@ -48,14 +55,15 @@ local save = function(option, output) output:option(option, "value") output:option(option, "use_sdlconfig") - output:option(option, "use_win32sdl") + output:option(option, "use_winlib") output:option(option, "use_osxframework") end local display = function(option) if option.value == true then if option.use_sdlconfig == true then return "using sdl-config" end - if option.use_win32sdl == true then return "using supplied win32 libraries" end + if option.use_winlib == 32 then return "using supplied win32 libraries" end + if option.use_winlib == 64 then return "using supplied win64 libraries" end if option.use_osxframework == true then return "using osx framework" end return "using unknown method" else diff -Nru teeworlds-0.6.1+dfsg/readme.txt teeworlds-0.6.2+dfsg/readme.txt --- teeworlds-0.6.1+dfsg/readme.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/readme.txt 2013-05-01 11:47:39.000000000 +0000 @@ -1,4 +1,4 @@ -Copyright (c) 2011 Magnus Auvinen +Copyright (c) 2012 Magnus Auvinen This software is provided 'as-is', without any express or implied diff -Nru teeworlds-0.6.1+dfsg/scripts/build.py teeworlds-0.6.2+dfsg/scripts/build.py --- teeworlds-0.6.1+dfsg/scripts/build.py 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/scripts/build.py 2013-05-01 11:47:39.000000000 +0000 @@ -12,7 +12,7 @@ os.chdir('../') url_bam = "http://github.com/matricks/bam/zipball/master" -url_teeworlds = "http://github.com/oy/teeworlds/zipball/master" +url_teeworlds = "http://github.com/teeworlds/teeworlds/zipball/master" release_type = "server_release client_release" arguments = OptionParser() diff -Nru teeworlds-0.6.1+dfsg/scripts/cmd5.py teeworlds-0.6.2+dfsg/scripts/cmd5.py --- teeworlds-0.6.1+dfsg/scripts/cmd5.py 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/scripts/cmd5.py 2013-05-01 11:47:39.000000000 +0000 @@ -30,6 +30,6 @@ hash = hashlib.md5(f).hexdigest().lower()[16:] #TODO 0.7: improve nethash creation -if hash == "63d6e69c6025feff": +if hash == "3dc531e4296de555": hash = "626fce9a778df4d4" print('#define GAME_NETVERSION_HASH "%s"' % hash) diff -Nru teeworlds-0.6.1+dfsg/scripts/make_release.py teeworlds-0.6.2+dfsg/scripts/make_release.py --- teeworlds-0.6.1+dfsg/scripts/make_release.py 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/scripts/make_release.py 2013-05-01 11:47:39.000000000 +0000 @@ -83,9 +83,16 @@ shutil.copy("configure.lua", package_dir) if use_bundle: - os.system("lipo -create -output "+name+"_srv "+name+"_srv"+"_ppc "+name+"_srv"+"_x86") - os.system("lipo -create -output "+name+" "+name+"_ppc "+name+"_x86") - os.system("lipo -create -output serverlaunch serverlaunch_ppc serverlaunch_x86") + bins = [name, name+'_srv', 'serverlaunch'] + platforms = ('x86', 'x86_64', 'ppc') + for bin in bins: + to_lipo = [] + for p in platforms: + fname = bin+'_'+p + if os.path.isfile(fname): + to_lipo.append(fname) + if to_lipo: + os.system("lipo -create -output "+bin+" "+" ".join(to_lipo)) # create Teeworlds appfolder clientbundle_content_dir = os.path.join(package_dir, "Teeworlds.app/Contents") diff -Nru teeworlds-0.6.1+dfsg/src/base/detect.h teeworlds-0.6.2+dfsg/src/base/detect.h --- teeworlds-0.6.1+dfsg/src/base/detect.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/base/detect.h 2013-05-01 11:47:39.000000000 +0000 @@ -63,7 +63,7 @@ #if defined(__sun) #define CONF_FAMILY_UNIX 1 #define CONF_FAMILY_STRING "unix" - #define CONF_PLATFROM_SOLARIS 1 + #define CONF_PLATFORM_SOLARIS 1 #define CONF_PLATFORM_STRING "solaris" #endif @@ -77,7 +77,7 @@ /* use gcc endianness definitions when available */ -#if defined(__GNUC__) && !defined(__APPLE__) +#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__MINGW32__) && !defined(__sun) #if defined(__FreeBSD__) || defined(__OpenBSD__) #include #else @@ -101,7 +101,7 @@ #endif #endif -#if defined(__ia64__) +#if defined(__ia64__) || defined(_M_IA64) #define CONF_ARCH_IA64 1 #define CONF_ARCH_STRING "ia64" #if !defined(CONF_ARCH_ENDIAN_LITTLE) && !defined(CONF_ARCH_ENDIAN_BIG) @@ -109,7 +109,7 @@ #endif #endif -#if defined(__amd64__) || defined(__x86_64__) +#if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) #define CONF_ARCH_AMD64 1 #define CONF_ARCH_STRING "amd64" #if !defined(CONF_ARCH_ENDIAN_LITTLE) && !defined(CONF_ARCH_ENDIAN_BIG) diff -Nru teeworlds-0.6.1+dfsg/src/base/system.c teeworlds-0.6.2+dfsg/src/base/system.c --- teeworlds-0.6.1+dfsg/src/base/system.c 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/base/system.c 2013-05-01 11:47:39.000000000 +0000 @@ -7,9 +7,7 @@ #include #include -/*#include "detect.h"*/ #include "system.h" -/*#include "e_console.h"*/ #if defined(CONF_FAMILY_UNIX) #include @@ -46,6 +44,10 @@ #error NOT IMPLEMENTED #endif +#if defined(CONF_PLATFORM_SOLARIS) + #include +#endif + #if defined(__cplusplus) extern "C" { #endif @@ -78,7 +80,7 @@ void dbg_break() { - *((unsigned*)0) = 0x0; + *((volatile unsigned*)0) = 0x0; } void dbg_msg(const char *sys, const char *fmt, ...) @@ -123,7 +125,7 @@ static void logger_file(const char *line) { io_write(logfile, line, strlen(line)); - io_write(logfile, "\n", 1); + io_write_newline(logfile); io_flush(logfile); } @@ -140,8 +142,6 @@ } /* */ -int memory_alloced = 0; - typedef struct MEMHEADER { const char *filename; @@ -163,8 +163,12 @@ { /* TODO: fix alignment */ /* TODO: add debugging */ + MEMTAIL *tail; MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL)); - MEMTAIL *tail = (struct MEMTAIL *)(((char*)(header+1))+size); + dbg_assert(header != 0, "mem_alloc failure"); + if(!header) + return NULL; + tail = (struct MEMTAIL *)(((char*)(header+1))+size); header->size = size; header->filename = filename; header->line = line; @@ -220,8 +224,9 @@ { while(header) { - str_format(buf, sizeof(buf), "%s(%d): %d\n", header->filename, header->line, header->size); + str_format(buf, sizeof(buf), "%s(%d): %d", header->filename, header->line, header->size); io_write(file, buf, strlen(buf)); + io_write_newline(file); header = header->next; } @@ -276,8 +281,13 @@ if(!filename || !length || filename[length-1] == '\\') return 0x0; handle = FindFirstFile(filename, &finddata); - if(handle == INVALID_HANDLE_VALUE || str_comp(filename+length-str_length(finddata.cFileName), finddata.cFileName)) + if(handle == INVALID_HANDLE_VALUE) return 0x0; + else if(str_comp(filename+length-str_length(finddata.cFileName), finddata.cFileName) != 0) + { + FindClose(handle); + return 0x0; + } FindClose(handle); #endif return (IOHANDLE)fopen(filename, "rb"); @@ -339,6 +349,15 @@ return fwrite(buffer, 1, size, (FILE*)io); } +unsigned io_write_newline(IOHANDLE io) +{ +#if defined(CONF_FAMILY_WINDOWS) + return fwrite("\r\n", 1, 2, (FILE*)io); +#else + return fwrite("\n", 1, 1, (FILE*)io); +#endif +} + int io_close(IOHANDLE io) { fclose((FILE*)io); @@ -460,7 +479,7 @@ #if defined(CONF_FAMILY_UNIX) return pthread_mutex_trylock((LOCKINTERNAL *)lock); #elif defined(CONF_FAMILY_WINDOWS) - return TryEnterCriticalSection((LPCRITICAL_SECTION)lock); + return !TryEnterCriticalSection((LPCRITICAL_SECTION)lock); #else #error not implemented on this platform #endif @@ -488,6 +507,23 @@ #endif } +#if !defined(CONF_PLATFORM_MACOSX) + #if defined(CONF_FAMILY_UNIX) + void semaphore_init(SEMAPHORE *sem) { sem_init(sem, 0, 0); } + void semaphore_wait(SEMAPHORE *sem) { sem_wait(sem); } + void semaphore_signal(SEMAPHORE *sem) { sem_post(sem); } + void semaphore_destroy(SEMAPHORE *sem) { sem_destroy(sem); } + #elif defined(CONF_FAMILY_WINDOWS) + void semaphore_init(SEMAPHORE *sem) { *sem = CreateSemaphore(0, 0, 10000, 0); } + void semaphore_wait(SEMAPHORE *sem) { WaitForSingleObject((HANDLE)*sem, INFINITE); } + void semaphore_signal(SEMAPHORE *sem) { ReleaseSemaphore((HANDLE)*sem, 1, NULL); } + void semaphore_destroy(SEMAPHORE *sem) { CloseHandle((HANDLE)*sem); } + #else + #error not implemented on this platform + #endif +#endif + + /* ----- time ----- */ int64 time_get() { @@ -578,18 +614,18 @@ return mem_comp(a, b, sizeof(NETADDR)); } -void net_addr_str(const NETADDR *addr, char *string, int max_length) +void net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port) { if(addr->type == NETTYPE_IPV4) { - if(addr->port != 0) + if(add_port != 0) str_format(string, max_length, "%d.%d.%d.%d:%d", addr->ip[0], addr->ip[1], addr->ip[2], addr->ip[3], addr->port); else str_format(string, max_length, "%d.%d.%d.%d", addr->ip[0], addr->ip[1], addr->ip[2], addr->ip[3]); } else if(addr->type == NETTYPE_IPV6) { - if(addr->port != 0) + if(add_port != 0) str_format(string, max_length, "[%x:%x:%x:%x:%x:%x:%x:%x]:%d", (addr->ip[0]<<8)|addr->ip[1], (addr->ip[2]<<8)|addr->ip[3], (addr->ip[4]<<8)|addr->ip[5], (addr->ip[6]<<8)|addr->ip[7], (addr->ip[8]<<8)|addr->ip[9], (addr->ip[10]<<8)|addr->ip[11], (addr->ip[12]<<8)|addr->ip[13], (addr->ip[14]<<8)|addr->ip[15], @@ -824,7 +860,15 @@ sock = socket(domain, type, 0); if(sock < 0) { +#if defined(CONF_FAMILY_WINDOWS) + char buf[128]; + int error = WSAGetLastError(); + if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, buf, sizeof(buf), 0) == 0) + buf[0] = 0; + dbg_msg("net", "failed to create socket with domain %d and type %d (%d '%s')", domain, type, error, buf); +#else dbg_msg("net", "failed to create socket with domain %d and type %d (%d '%s')", domain, type, errno, strerror(errno)); +#endif return -1; } @@ -841,7 +885,15 @@ e = bind(sock, addr, sockaddrlen); if(e != 0) { +#if defined(CONF_FAMILY_WINDOWS) + char buf[128]; + int error = WSAGetLastError(); + if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, buf, sizeof(buf), 0) == 0) + buf[0] = 0; + dbg_msg("net", "failed to bind socket with domain %d and type %d (%d '%s')", domain, type, error, buf); +#else dbg_msg("net", "failed to bind socket with domain %d and type %d (%d '%s')", domain, type, errno, strerror(errno)); +#endif priv_net_close_socket(sock); return -1; } @@ -855,6 +907,7 @@ NETSOCKET sock = invalid_socket; NETADDR tmpbindaddr = bindaddr; int broadcast = 1; + int recvsize = 65536; if(bindaddr.type&NETTYPE_IPV4) { @@ -869,13 +922,13 @@ { sock.type |= NETTYPE_IPV4; sock.ipv4sock = socket; - } - /* set non-blocking */ - net_set_non_blocking(sock); + /* set boardcast */ + setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)); - /* set boardcast */ - setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)); + /* set receive buffer size */ + setsockopt(socket, SOL_SOCKET, SO_RCVBUF, (char*)&recvsize, sizeof(recvsize)); + } } if(bindaddr.type&NETTYPE_IPV6) @@ -891,15 +944,18 @@ { sock.type |= NETTYPE_IPV6; sock.ipv6sock = socket; - } - /* set non-blocking */ - net_set_non_blocking(sock); + /* set boardcast */ + setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)); - /* set boardcast */ - setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)); + /* set receive buffer size */ + setsockopt(socket, SOL_SOCKET, SO_RCVBUF, (char*)&recvsize, sizeof(recvsize)); + } } + /* set non-blocking */ + net_set_non_blocking(sock); + /* return */ return sock; } @@ -1119,7 +1175,7 @@ sockaddr_len = sizeof(addr); s = accept(sock.ipv4sock, (struct sockaddr *)&addr, &sockaddr_len); - + if (s != -1) { sockaddr_to_netaddr((const struct sockaddr *)&addr, a); @@ -1135,7 +1191,7 @@ sockaddr_len = sizeof(addr); s = accept(sock.ipv6sock, (struct sockaddr *)&addr, &sockaddr_len); - + if (s != -1) { sockaddr_to_netaddr((const struct sockaddr *)&addr, a); @@ -1186,7 +1242,7 @@ bytes = send((int)sock.ipv4sock, (const char*)data, size, 0); if(sock.ipv6sock >= 0) bytes = send((int)sock.ipv6sock, (const char*)data, size, 0); - + return bytes; } @@ -1198,7 +1254,7 @@ bytes = recv((int)sock.ipv4sock, (char*)data, maxsize, 0); if(sock.ipv6sock >= 0) bytes = recv((int)sock.ipv6sock, (char*)data, maxsize, 0); - + return bytes; } @@ -1477,7 +1533,7 @@ return 0; } -unsigned time_timestamp() +int time_timestamp() { return time(0); } @@ -1773,6 +1829,27 @@ float str_tofloat(const char *str) { return atof(str); } +const char *str_utf8_skip_whitespaces(const char *str) +{ + const char *str_old; + int code; + + while(*str) + { + str_old = str; + code = str_utf8_decode(&str); + + // check if unicode is not empty + if(code > 0x20 && code != 0xA0 && code != 0x034F && (code < 0x2000 || code > 0x200F) && (code < 0x2028 || code > 0x202F) && + (code < 0x205F || code > 0x2064) && (code < 0x206A || code > 0x206F) && (code < 0xFE00 || code > 0xFE0F) && + code != 0xFEFF && (code < 0xFFF9 || code > 0xFFFC)) + { + return str_old; + } + } + + return str; +} static int str_utf8_isstart(char c) { diff -Nru teeworlds-0.6.1+dfsg/src/base/system.h teeworlds-0.6.2+dfsg/src/base/system.h --- teeworlds-0.6.1+dfsg/src/base/system.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/base/system.h 2013-05-01 11:47:39.000000000 +0000 @@ -33,6 +33,13 @@ #define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg) void dbg_assert_imp(const char *filename, int line, int test, const char *msg); + +#ifdef __clang_analyzer__ +#include +#undef dbg_assert +#define dbg_assert(test,msg) assert(test) +#endif + /* Function: dbg_break Breaks into the debugger. @@ -240,6 +247,18 @@ unsigned io_write(IOHANDLE io, const void *buffer, unsigned size); /* + Function: io_write_newline + Writes newline to file. + + Parameters: + io - Handle to the file. + + Returns: + Number of bytes written. +*/ +unsigned io_write_newline(IOHANDLE io); + +/* Function: io_seek Seeks to a specified offset in the file. @@ -388,6 +407,25 @@ void lock_wait(LOCK lock); void lock_release(LOCK lock); + +/* Group: Semaphores */ + +#if !defined(CONF_PLATFORM_MACOSX) + #if defined(CONF_FAMILY_UNIX) + #include + typedef sem_t SEMAPHORE; + #elif defined(CONF_FAMILY_WINDOWS) + typedef void* SEMAPHORE; + #else + #error missing sempahore implementation + #endif + + void semaphore_init(SEMAPHORE *sem); + void semaphore_wait(SEMAPHORE *sem); + void semaphore_signal(SEMAPHORE *sem); + void semaphore_destroy(SEMAPHORE *sem); +#endif + /* Group: Timer */ #ifdef __GNUC__ /* if compiled with -pedantic-errors it will complain about long @@ -425,7 +463,7 @@ Returns: The time as a UNIX timestamp */ -unsigned time_timestamp(); +int time_timestamp(); /* Group: Network General */ typedef struct @@ -499,12 +537,13 @@ addr - Address to turn into a string. string - Buffer to fill with the string. max_length - Maximum size of the string. + add_port - add port to string or not Remarks: - The string will always be zero terminated */ -void net_addr_str(const NETADDR *addr, char *string, int max_length); +void net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port); /* Function: net_addr_from_str @@ -1130,25 +1169,6 @@ void swap_endian(void *data, unsigned elem_size, unsigned num); -/* Group: Debug levels */ -//by format -enum { - DBG_FMT_RAW = 1, //raw output - DBG_FMT_TIME = 2, //show time - DBG_FMT_SYS = 3, //show sys - DBG_FMT_FULL = 4 //show both -}; - -enum { - DBG_LEVEL_IMPORTANT = 0, //important always showed messages - DBG_LEVEL_ERROR = 1, //error messages - DBG_LEVEL_WARNING = 2, //warning messages - DBG_LEVEL_MSG = 3, //extra debug messages - DBG_LEVEL_INFO = 4 //info messages -}; - -#define DBG_LEVEL_LOW DBG_LEVEL_IMPORTANT -#define DBG_LEVEL_HIGH DBG_LEVEL_INFO typedef void (*DBG_LOGGER)(const char *line); void dbg_logger(DBG_LOGGER logger); @@ -1193,6 +1213,7 @@ */ void gui_messagebox(const char *title, const char *message); +const char *str_utf8_skip_whitespaces(const char *str); /* Function: str_utf8_rewind diff -Nru teeworlds-0.6.1+dfsg/src/base/tl/base.h teeworlds-0.6.2+dfsg/src/base/tl/base.h --- teeworlds-0.6.1+dfsg/src/base/tl/base.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/base/tl/base.h 2013-05-01 11:47:39.000000000 +0000 @@ -5,7 +5,7 @@ #include -inline void assert(bool statement) +inline void tl_assert(bool statement) { dbg_assert(statement, "assert!"); } diff -Nru teeworlds-0.6.1+dfsg/src/base/tl/range.h teeworlds-0.6.2+dfsg/src/base/tl/range.h --- teeworlds-0.6.1+dfsg/src/base/tl/range.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/base/tl/range.h 2013-05-01 11:47:39.000000000 +0000 @@ -150,11 +150,11 @@ } bool empty() const { return begin >= end; } - void pop_front() { assert(!empty()); begin++; } - void pop_back() { assert(!empty()); end--; } - T& front() { assert(!empty()); return *begin; } - T& back() { assert(!empty()); return *(end-1); } - T& index(unsigned i) { assert(i >= 0 && i < (unsigned)(end-begin)); return begin[i]; } + void pop_front() { tl_assert(!empty()); begin++; } + void pop_back() { tl_assert(!empty()); end--; } + T& front() { tl_assert(!empty()); return *begin; } + T& back() { tl_assert(!empty()); return *(end-1); } + T& index(unsigned i) { tl_assert(i < (unsigned)(end-begin)); return begin[i]; } unsigned size() const { return (unsigned)(end-begin); } plain_range slice(unsigned startindex, unsigned endindex) { diff -Nru teeworlds-0.6.1+dfsg/src/base/tl/threading.h teeworlds-0.6.2+dfsg/src/base/tl/threading.h --- teeworlds-0.6.1+dfsg/src/base/tl/threading.h 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/base/tl/threading.h 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,115 @@ + +#pragma once + +#include "../system.h" + +/* + atomic_inc - should return the value after increment + atomic_dec - should return the value after decrement + atomic_compswap - should return the value before the eventual swap + sync_barrier - creates a full hardware fence +*/ + +#if defined(__GNUC__) + + inline unsigned atomic_inc(volatile unsigned *pValue) + { + return __sync_add_and_fetch(pValue, 1); + } + + inline unsigned atomic_dec(volatile unsigned *pValue) + { + return __sync_add_and_fetch(pValue, -1); + } + + inline unsigned atomic_compswap(volatile unsigned *pValue, unsigned comperand, unsigned value) + { + return __sync_val_compare_and_swap(pValue, comperand, value); + } + + inline void sync_barrier() + { + __sync_synchronize(); + } + +#elif defined(_MSC_VER) + #include + + #define WIN32_LEAN_AND_MEAN + #include + + inline unsigned atomic_inc(volatile unsigned *pValue) + { + return _InterlockedIncrement((volatile long *)pValue); + } + + inline unsigned atomic_dec(volatile unsigned *pValue) + { + return _InterlockedDecrement((volatile long *)pValue); + } + + inline unsigned atomic_compswap(volatile unsigned *pValue, unsigned comperand, unsigned value) + { + return _InterlockedCompareExchange((volatile long *)pValue, (long)value, (long)comperand); + } + + inline void sync_barrier() + { + MemoryBarrier(); + } +#else + #error missing atomic implementation for this compiler +#endif + +#if defined(CONF_PLATFORM_MACOSX) + /* + use semaphore provided by SDL on macosx + */ +#else + class semaphore + { + SEMAPHORE sem; + public: + semaphore() { semaphore_init(&sem); } + ~semaphore() { semaphore_destroy(&sem); } + void wait() { semaphore_wait(&sem); } + void signal() { semaphore_signal(&sem); } + }; +#endif + +class lock +{ + friend class scope_lock; + + LOCK var; + + void take() { lock_wait(var); } + void release() { lock_release(var); } + +public: + lock() + { + var = lock_create(); + } + + ~lock() + { + lock_destroy(var); + } +}; + +class scope_lock +{ + lock *var; +public: + scope_lock(lock *l) + { + var = l; + var->take(); + } + + ~scope_lock() + { + var->release(); + } +}; diff -Nru teeworlds-0.6.1+dfsg/src/base/vmath.h teeworlds-0.6.2+dfsg/src/base/vmath.h --- teeworlds-0.6.1+dfsg/src/base/vmath.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/base/vmath.h 2013-05-01 11:47:39.000000000 +0000 @@ -25,12 +25,18 @@ vector2_base operator -(const vector2_base &v) const { return vector2_base(x-v.x, y-v.y); } vector2_base operator +(const vector2_base &v) const { return vector2_base(x+v.x, y+v.y); } vector2_base operator *(const T v) const { return vector2_base(x*v, y*v); } + vector2_base operator *(const vector2_base &v) const { return vector2_base(x*v.x, y*v.y); } + vector2_base operator /(const T v) const { return vector3_base(x/v, y/v); } + vector2_base operator /(const vector2_base &v) const { return vector2_base(x/v.x, y/v.y); } const vector2_base &operator =(const vector2_base &v) { x = v.x; y = v.y; return *this; } const vector2_base &operator +=(const vector2_base &v) { x += v.x; y += v.y; return *this; } const vector2_base &operator -=(const vector2_base &v) { x -= v.x; y -= v.y; return *this; } const vector2_base &operator *=(const T v) { x *= v; y *= v; return *this; } + const vector2_base &operator *=(const vector2_base &v) { x *= v.x; y *= v.y; return *this; } + const vector2_base &operator /=(const T v) { x /= v; y /= v; return *this; } + const vector2_base &operator /=(const vector2_base &v) { x /= v.x; y /= v.y; return *this; } bool operator ==(const vector2_base &v) const { return x == v.x && y == v.y; } //TODO: do this with an eps instead @@ -107,10 +113,14 @@ vector3_base operator *(const T v) const { return vector3_base(x*v, y*v, z*v); } vector3_base operator *(const vector3_base &v) const { return vector3_base(x*v.x, y*v.y, z*v.z); } vector3_base operator /(const T v) const { return vector3_base(x/v, y/v, z/v); } + vector3_base operator /(const vector3_base &v) const { return vector3_base(x/v.x, y/v.y, z/v.z); } const vector3_base &operator +=(const vector3_base &v) { x += v.x; y += v.y; z += v.z; return *this; } const vector3_base &operator -=(const vector3_base &v) { x -= v.x; y -= v.y; z -= v.z; return *this; } const vector3_base &operator *=(const T v) { x *= v; y *= v; z *= v; return *this; } + const vector3_base &operator *=(const vector3_base &v) { x *= v.x; y *= v.y; z *= v.z; return *this; } + const vector3_base &operator /=(const T v) { x /= v; y /= v; z /= v; return *this; } + const vector3_base &operator /=(const vector3_base &v) { x /= v.x; y /= v.y; z /= v.z; return *this; } bool operator ==(const vector3_base &v) const { return x == v.x && y == v.y && z == v.z; } //TODO: do this with an eps instead @@ -180,12 +190,17 @@ vector4_base operator -() const { return vector4_base(-x, -y, -z, -w); } vector4_base operator *(const vector4_base &v) const { return vector4_base(x*v.x, y*v.y, z*v.z, w*v.w); } vector4_base operator *(const T v) const { return vector4_base(x*v, y*v, z*v, w*v); } + vector4_base operator /(const vector4_base &v) const { return vector4_base(x/v.x, y/v.y, z/v.z, w/v.w); } + vector4_base operator /(const T v) const { return vector4_base(x/v, y/v, z/v, w/v); } const vector4_base &operator =(const vector4_base &v) { x = v.x; y = v.y; z = v.z; w = v.w; return *this; } const vector4_base &operator +=(const vector4_base &v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; } const vector4_base &operator -=(const vector4_base &v) { x -= v.x; y -= v.y; z -= v.z; w -= v.w; return *this; } const vector4_base &operator *=(const T v) { x *= v; y *= v; z *= v; w *= v; return *this; } + const vector4_base &operator *=(const vector4_base &v) { x *= v.x; y *= v.y; z *= v.z; w *= v.w; return *this; } + const vector4_base &operator /=(const T v) { x /= v; y /= v; z /= v; w /= v; return *this; } + const vector4_base &operator /=(const vector4_base &v) { x /= v.x; y /= v.y; z /= v.z; w /= v.w; return *this; } bool operator ==(const vector4_base &v) const { return x == v.x && y == v.y && z == v.z && w == v.w; } //TODO: do this with an eps instead diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/backend_sdl.cpp teeworlds-0.6.2+dfsg/src/engine/client/backend_sdl.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/backend_sdl.cpp 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/backend_sdl.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,636 @@ + +#include "SDL.h" +#include "SDL_opengl.h" + +#include + +#include "graphics_threaded.h" +#include "backend_sdl.h" + +// ------------ CGraphicsBackend_Threaded + +void CGraphicsBackend_Threaded::ThreadFunc(void *pUser) +{ + #ifdef CONF_PLATFORM_MACOSX + CAutoreleasePool AutoreleasePool; + #endif + CGraphicsBackend_Threaded *pThis = (CGraphicsBackend_Threaded *)pUser; + + while(!pThis->m_Shutdown) + { + pThis->m_Activity.wait(); + if(pThis->m_pBuffer) + { + pThis->m_pProcessor->RunBuffer(pThis->m_pBuffer); + sync_barrier(); + pThis->m_pBuffer = 0x0; + pThis->m_BufferDone.signal(); + } + } +} + +CGraphicsBackend_Threaded::CGraphicsBackend_Threaded() +{ + m_pBuffer = 0x0; + m_pProcessor = 0x0; + m_pThread = 0x0; +} + +void CGraphicsBackend_Threaded::StartProcessor(ICommandProcessor *pProcessor) +{ + m_Shutdown = false; + m_pProcessor = pProcessor; + m_pThread = thread_create(ThreadFunc, this); + m_BufferDone.signal(); +} + +void CGraphicsBackend_Threaded::StopProcessor() +{ + m_Shutdown = true; + m_Activity.signal(); + thread_wait(m_pThread); + thread_destroy(m_pThread); +} + +void CGraphicsBackend_Threaded::RunBuffer(CCommandBuffer *pBuffer) +{ + WaitForIdle(); + m_pBuffer = pBuffer; + m_Activity.signal(); +} + +bool CGraphicsBackend_Threaded::IsIdle() const +{ + return m_pBuffer == 0x0; +} + +void CGraphicsBackend_Threaded::WaitForIdle() +{ + while(m_pBuffer != 0x0) + m_BufferDone.wait(); +} + + +// ------------ CCommandProcessorFragment_General + +void CCommandProcessorFragment_General::Cmd_Signal(const CCommandBuffer::SCommand_Signal *pCommand) +{ + pCommand->m_pSemaphore->signal(); +} + +bool CCommandProcessorFragment_General::RunCommand(const CCommandBuffer::SCommand * pBaseCommand) +{ + switch(pBaseCommand->m_Cmd) + { + case CCommandBuffer::CMD_NOP: break; + case CCommandBuffer::CMD_SIGNAL: Cmd_Signal(static_cast(pBaseCommand)); break; + default: return false; + } + + return true; +} + +// ------------ CCommandProcessorFragment_OpenGL + +int CCommandProcessorFragment_OpenGL::TexFormatToOpenGLFormat(int TexFormat) +{ + if(TexFormat == CCommandBuffer::TEXFORMAT_RGB) return GL_RGB; + if(TexFormat == CCommandBuffer::TEXFORMAT_ALPHA) return GL_ALPHA; + if(TexFormat == CCommandBuffer::TEXFORMAT_RGBA) return GL_RGBA; + return GL_RGBA; +} + +unsigned char CCommandProcessorFragment_OpenGL::Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp) +{ + int Value = 0; + for(int x = 0; x < ScaleW; x++) + for(int y = 0; y < ScaleH; y++) + Value += pData[((v+y)*w+(u+x))*Bpp+Offset]; + return Value/(ScaleW*ScaleH); +} + +void *CCommandProcessorFragment_OpenGL::Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData) +{ + unsigned char *pTmpData; + int ScaleW = Width/NewWidth; + int ScaleH = Height/NewHeight; + + int Bpp = 3; + if(Format == CCommandBuffer::TEXFORMAT_RGBA) + Bpp = 4; + + pTmpData = (unsigned char *)mem_alloc(NewWidth*NewHeight*Bpp, 1); + + int c = 0; + for(int y = 0; y < NewHeight; y++) + for(int x = 0; x < NewWidth; x++, c++) + { + pTmpData[c*Bpp] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 0, ScaleW, ScaleH, Bpp); + pTmpData[c*Bpp+1] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 1, ScaleW, ScaleH, Bpp); + pTmpData[c*Bpp+2] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 2, ScaleW, ScaleH, Bpp); + if(Bpp == 4) + pTmpData[c*Bpp+3] = Sample(Width, Height, pData, x*ScaleW, y*ScaleH, 3, ScaleW, ScaleH, Bpp); + } + + return pTmpData; +} + +void CCommandProcessorFragment_OpenGL::SetState(const CCommandBuffer::SState &State) +{ + // blend + switch(State.m_BlendMode) + { + case CCommandBuffer::BLEND_NONE: + glDisable(GL_BLEND); + break; + case CCommandBuffer::BLEND_ALPHA: + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + break; + case CCommandBuffer::BLEND_ADDITIVE: + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + break; + default: + dbg_msg("render", "unknown blendmode %d\n", State.m_BlendMode); + }; + + // clip + if(State.m_ClipEnable) + { + glScissor(State.m_ClipX, State.m_ClipY, State.m_ClipW, State.m_ClipH); + glEnable(GL_SCISSOR_TEST); + } + else + glDisable(GL_SCISSOR_TEST); + + // texture + if(State.m_Texture >= 0 && State.m_Texture < CCommandBuffer::MAX_TEXTURES) + { + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, m_aTextures[State.m_Texture].m_Tex); + } + else + glDisable(GL_TEXTURE_2D); + + switch(State.m_WrapMode) + { + case CCommandBuffer::WRAP_REPEAT: + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + break; + case CCommandBuffer::WRAP_CLAMP: + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + break; + default: + dbg_msg("render", "unknown wrapmode %d\n", State.m_WrapMode); + }; + + // screen mapping + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(State.m_ScreenTL.x, State.m_ScreenBR.x, State.m_ScreenBR.y, State.m_ScreenTL.y, 1.0f, 10.f); +} + +void CCommandProcessorFragment_OpenGL::Cmd_Init(const SCommand_Init *pCommand) +{ + m_pTextureMemoryUsage = pCommand->m_pTextureMemoryUsage; +} + +void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) +{ + glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); + glTexSubImage2D(GL_TEXTURE_2D, 0, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height, + TexFormatToOpenGLFormat(pCommand->m_Format), GL_UNSIGNED_BYTE, pCommand->m_pData); + mem_free(pCommand->m_pData); +} + +void CCommandProcessorFragment_OpenGL::Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand) +{ + glDeleteTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); + *m_pTextureMemoryUsage -= m_aTextures[pCommand->m_Slot].m_MemSize; +} + +void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) +{ + int Width = pCommand->m_Width; + int Height = pCommand->m_Height; + void *pTexData = pCommand->m_pData; + + // resample if needed + if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB) + { + int MaxTexSize; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize); + if(Width > MaxTexSize || Height > MaxTexSize) + { + do + { + Width>>=1; + Height>>=1; + } + while(Width > MaxTexSize || Height > MaxTexSize); + + void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast(pCommand->m_pData)); + mem_free(pTexData); + pTexData = pTmpData; + } + else if(Width > 16 && Height > 16 && (pCommand->m_Flags&CCommandBuffer::TEXFLAG_QUALITY) == 0) + { + Width>>=1; + Height>>=1; + + void *pTmpData = Rescale(pCommand->m_Width, pCommand->m_Height, Width, Height, pCommand->m_Format, static_cast(pCommand->m_pData)); + mem_free(pTexData); + pTexData = pTmpData; + } + } + + int Oglformat = TexFormatToOpenGLFormat(pCommand->m_Format); + int StoreOglformat = TexFormatToOpenGLFormat(pCommand->m_StoreFormat); + + if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_COMPRESSED) + { + switch(StoreOglformat) + { + case GL_RGB: StoreOglformat = GL_COMPRESSED_RGB_ARB; break; + case GL_ALPHA: StoreOglformat = GL_COMPRESSED_ALPHA_ARB; break; + case GL_RGBA: StoreOglformat = GL_COMPRESSED_RGBA_ARB; break; + default: StoreOglformat = GL_COMPRESSED_RGBA_ARB; + } + } + glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); + glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); + + if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pTexData); + } + + // calculate memory usage + m_aTextures[pCommand->m_Slot].m_MemSize = Width*Height*pCommand->m_PixelSize; + while(Width > 2 && Height > 2) + { + Width>>=1; + Height>>=1; + m_aTextures[pCommand->m_Slot].m_MemSize += Width*Height*pCommand->m_PixelSize; + } + *m_pTextureMemoryUsage += m_aTextures[pCommand->m_Slot].m_MemSize; + + mem_free(pTexData); +} + +void CCommandProcessorFragment_OpenGL::Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand) +{ + glClearColor(pCommand->m_Color.r, pCommand->m_Color.g, pCommand->m_Color.b, 0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +void CCommandProcessorFragment_OpenGL::Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand) +{ + SetState(pCommand->m_State); + + glVertexPointer(3, GL_FLOAT, sizeof(CCommandBuffer::SVertex), (char*)pCommand->m_pVertices); + glTexCoordPointer(2, GL_FLOAT, sizeof(CCommandBuffer::SVertex), (char*)pCommand->m_pVertices + sizeof(float)*3); + glColorPointer(4, GL_FLOAT, sizeof(CCommandBuffer::SVertex), (char*)pCommand->m_pVertices + sizeof(float)*5); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + switch(pCommand->m_PrimType) + { + case CCommandBuffer::PRIMTYPE_QUADS: + glDrawArrays(GL_QUADS, 0, pCommand->m_PrimCount*4); + break; + case CCommandBuffer::PRIMTYPE_LINES: + glDrawArrays(GL_LINES, 0, pCommand->m_PrimCount*2); + break; + default: + dbg_msg("render", "unknown primtype %d\n", pCommand->m_Cmd); + }; +} + +void CCommandProcessorFragment_OpenGL::Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand) +{ + // fetch image data + GLint aViewport[4] = {0,0,0,0}; + glGetIntegerv(GL_VIEWPORT, aViewport); + + int w = aViewport[2]; + int h = aViewport[3]; + + // we allocate one more row to use when we are flipping the texture + unsigned char *pPixelData = (unsigned char *)mem_alloc(w*(h+1)*3, 1); + unsigned char *pTempRow = pPixelData+w*h*3; + + // fetch the pixels + GLint Alignment; + glGetIntegerv(GL_PACK_ALIGNMENT, &Alignment); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0,0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData); + glPixelStorei(GL_PACK_ALIGNMENT, Alignment); + + // flip the pixel because opengl works from bottom left corner + for(int y = 0; y < h/2; y++) + { + mem_copy(pTempRow, pPixelData+y*w*3, w*3); + mem_copy(pPixelData+y*w*3, pPixelData+(h-y-1)*w*3, w*3); + mem_copy(pPixelData+(h-y-1)*w*3, pTempRow,w*3); + } + + // fill in the information + pCommand->m_pImage->m_Width = w; + pCommand->m_pImage->m_Height = h; + pCommand->m_pImage->m_Format = CImageInfo::FORMAT_RGB; + pCommand->m_pImage->m_pData = pPixelData; +} + +CCommandProcessorFragment_OpenGL::CCommandProcessorFragment_OpenGL() +{ + mem_zero(m_aTextures, sizeof(m_aTextures)); + m_pTextureMemoryUsage = 0; +} + +bool CCommandProcessorFragment_OpenGL::RunCommand(const CCommandBuffer::SCommand * pBaseCommand) +{ + switch(pBaseCommand->m_Cmd) + { + case CMD_INIT: Cmd_Init(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_TEXTURE_CREATE: Cmd_Texture_Create(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_TEXTURE_DESTROY: Cmd_Texture_Destroy(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_TEXTURE_UPDATE: Cmd_Texture_Update(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_CLEAR: Cmd_Clear(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_RENDER: Cmd_Render(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_SCREENSHOT: Cmd_Screenshot(static_cast(pBaseCommand)); break; + default: return false; + } + + return true; +} + + +// ------------ CCommandProcessorFragment_SDL + +void CCommandProcessorFragment_SDL::Cmd_Init(const SCommand_Init *pCommand) +{ + m_GLContext = pCommand->m_Context; + GL_MakeCurrent(m_GLContext); + + // set some default settings + glEnable(GL_BLEND); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glAlphaFunc(GL_GREATER, 0); + glEnable(GL_ALPHA_TEST); + glDepthMask(0); +} + +void CCommandProcessorFragment_SDL::Cmd_Shutdown(const SCommand_Shutdown *pCommand) +{ + GL_ReleaseContext(m_GLContext); +} + +void CCommandProcessorFragment_SDL::Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand) +{ + GL_SwapBuffers(m_GLContext); + + if(pCommand->m_Finish) + glFinish(); +} + +void CCommandProcessorFragment_SDL::Cmd_VideoModes(const CCommandBuffer::SCommand_VideoModes *pCommand) +{ + // TODO: fix this code on osx or windows + SDL_Rect **ppModes = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN); + if(ppModes == NULL) + { + // no modes + *pCommand->m_pNumModes = 0; + } + else if(ppModes == (SDL_Rect**)-1) + { + // no modes + *pCommand->m_pNumModes = 0; + } + else + { + int NumModes = 0; + for(int i = 0; ppModes[i]; ++i) + { + if(NumModes == pCommand->m_MaxModes) + break; + pCommand->m_pModes[NumModes].m_Width = ppModes[i]->w; + pCommand->m_pModes[NumModes].m_Height = ppModes[i]->h; + pCommand->m_pModes[NumModes].m_Red = 8; + pCommand->m_pModes[NumModes].m_Green = 8; + pCommand->m_pModes[NumModes].m_Blue = 8; + NumModes++; + } + + *pCommand->m_pNumModes = NumModes; + } +} + +CCommandProcessorFragment_SDL::CCommandProcessorFragment_SDL() +{ +} + +bool CCommandProcessorFragment_SDL::RunCommand(const CCommandBuffer::SCommand *pBaseCommand) +{ + switch(pBaseCommand->m_Cmd) + { + case CCommandBuffer::CMD_SWAP: Cmd_Swap(static_cast(pBaseCommand)); break; + case CCommandBuffer::CMD_VIDEOMODES: Cmd_VideoModes(static_cast(pBaseCommand)); break; + case CMD_INIT: Cmd_Init(static_cast(pBaseCommand)); break; + case CMD_SHUTDOWN: Cmd_Shutdown(static_cast(pBaseCommand)); break; + default: return false; + } + + return true; +} + +// ------------ CCommandProcessor_SDL_OpenGL + +void CCommandProcessor_SDL_OpenGL::RunBuffer(CCommandBuffer *pBuffer) +{ + unsigned CmdIndex = 0; + while(1) + { + const CCommandBuffer::SCommand *pBaseCommand = pBuffer->GetCommand(&CmdIndex); + if(pBaseCommand == 0x0) + break; + + if(m_OpenGL.RunCommand(pBaseCommand)) + continue; + + if(m_SDL.RunCommand(pBaseCommand)) + continue; + + if(m_General.RunCommand(pBaseCommand)) + continue; + + dbg_msg("graphics", "unknown command %d", pBaseCommand->m_Cmd); + } +} + +// ------------ CGraphicsBackend_SDL_OpenGL + +int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) +{ + if(!SDL_WasInit(SDL_INIT_VIDEO)) + { + if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) + { + dbg_msg("gfx", "unable to init SDL video: %s", SDL_GetError()); + return -1; + } + + #ifdef CONF_FAMILY_WINDOWS + if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) // ignore_convention + putenv("SDL_VIDEO_WINDOW_POS=center"); // ignore_convention + #endif + } + + const SDL_VideoInfo *pInfo = SDL_GetVideoInfo(); + SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // prevent stuck mouse cursor sdl-bug when loosing fullscreen focus in windows + + // use current resolution as default + if(*Width == 0 || *Height == 0) + { + *Width = pInfo->current_w; + *Height = pInfo->current_h; + } + + // set flags + int SdlFlags = SDL_OPENGL; + if(Flags&IGraphicsBackend::INITFLAG_RESIZABLE) + SdlFlags |= SDL_RESIZABLE; + + if(pInfo->hw_available) // ignore_convention + SdlFlags |= SDL_HWSURFACE; + else + SdlFlags |= SDL_SWSURFACE; + + if(pInfo->blit_hw) // ignore_convention + SdlFlags |= SDL_HWACCEL; + + dbg_assert(!(Flags&IGraphicsBackend::INITFLAG_BORDERLESS) + || !(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN), + "only one of borderless and fullscreen may be activated at the same time"); + + if(Flags&IGraphicsBackend::INITFLAG_BORDERLESS) + SdlFlags |= SDL_NOFRAME; + + if(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN) + SdlFlags |= SDL_FULLSCREEN; + + // set gl attributes + if(FsaaSamples) + { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, FsaaSamples); + } + else + { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + } + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, Flags&IGraphicsBackend::INITFLAG_VSYNC ? 1 : 0); + + // set caption + SDL_WM_SetCaption(pName, pName); + + // create window + m_pScreenSurface = SDL_SetVideoMode(*Width, *Height, 0, SdlFlags); + if(!m_pScreenSurface) + { + dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError()); + //*pCommand->m_pResult = -1; + return -1; + } + + SDL_ShowCursor(0); + + // fetch gl contexts and release the context from this thread + m_GLContext = GL_GetCurrentContext(); + GL_ReleaseContext(m_GLContext); + + // start the command processor + m_pProcessor = new CCommandProcessor_SDL_OpenGL; + StartProcessor(m_pProcessor); + + // issue init commands for OpenGL and SDL + CCommandBuffer CmdBuffer(1024, 512); + CCommandProcessorFragment_OpenGL::SCommand_Init CmdOpenGL; + CmdOpenGL.m_pTextureMemoryUsage = &m_TextureMemoryUsage; + CmdBuffer.AddCommand(CmdOpenGL); + CCommandProcessorFragment_SDL::SCommand_Init CmdSDL; + CmdSDL.m_Context = m_GLContext; + CmdBuffer.AddCommand(CmdSDL); + RunBuffer(&CmdBuffer); + WaitForIdle(); + + // return + return 0; +} + +int CGraphicsBackend_SDL_OpenGL::Shutdown() +{ + // issue a shutdown command + CCommandBuffer CmdBuffer(1024, 512); + CCommandProcessorFragment_SDL::SCommand_Shutdown Cmd; + CmdBuffer.AddCommand(Cmd); + RunBuffer(&CmdBuffer); + WaitForIdle(); + + // stop and delete the processor + StopProcessor(); + delete m_pProcessor; + m_pProcessor = 0; + + SDL_QuitSubSystem(SDL_INIT_VIDEO); + return 0; +} + +int CGraphicsBackend_SDL_OpenGL::MemoryUsage() const +{ + return m_TextureMemoryUsage; +} + +void CGraphicsBackend_SDL_OpenGL::Minimize() +{ + SDL_WM_IconifyWindow(); +} + +void CGraphicsBackend_SDL_OpenGL::Maximize() +{ + // TODO: SDL +} + +int CGraphicsBackend_SDL_OpenGL::WindowActive() +{ + return SDL_GetAppState()&SDL_APPINPUTFOCUS; +} + +int CGraphicsBackend_SDL_OpenGL::WindowOpen() +{ + return SDL_GetAppState()&SDL_APPACTIVE; + +} + + +IGraphicsBackend *CreateGraphicsBackend() { return new CGraphicsBackend_SDL_OpenGL; } diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/backend_sdl.h teeworlds-0.6.2+dfsg/src/engine/client/backend_sdl.h --- teeworlds-0.6.1+dfsg/src/engine/client/backend_sdl.h 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/backend_sdl.h 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,272 @@ + +#include "SDL.h" +#include "SDL_opengl.h" + +#include "graphics_threaded.h" + + + +// platform dependent implementations for transfering render context from the main thread to the graphics thread +// TODO: when SDL 1.3 comes, this can be removed +#if defined(CONF_FAMILY_WINDOWS) + struct SGLContext + { + HDC m_hDC; + HGLRC m_hGLRC; + }; + + static SGLContext GL_GetCurrentContext() + { + SGLContext Context; + Context.m_hDC = wglGetCurrentDC(); + Context.m_hGLRC = wglGetCurrentContext(); + return Context; + } + + static void GL_MakeCurrent(const SGLContext &Context) { wglMakeCurrent(Context.m_hDC, Context.m_hGLRC); } + static void GL_ReleaseContext(const SGLContext &Context) { wglMakeCurrent(NULL, NULL); } + static void GL_SwapBuffers(const SGLContext &Context) { SwapBuffers(Context.m_hDC); } +#elif defined(CONF_PLATFORM_MACOSX) + + #include + + class semaphore + { + SDL_sem *sem; + public: + semaphore() { sem = SDL_CreateSemaphore(0); } + ~semaphore() { SDL_DestroySemaphore(sem); } + void wait() { SDL_SemWait(sem); } + void signal() { SDL_SemPost(sem); } + }; + + struct SGLContext + { + id m_Context; + }; + + static SGLContext GL_GetCurrentContext() + { + SGLContext Context; + Class NSOpenGLContextClass = (Class) objc_getClass("NSOpenGLContext"); + SEL selector = sel_registerName("currentContext"); + Context.m_Context = objc_msgSend((objc_object*) NSOpenGLContextClass, selector); + return Context; + } + + static void GL_MakeCurrent(const SGLContext &Context) + { + SEL selector = sel_registerName("makeCurrentContext"); + objc_msgSend(Context.m_Context, selector); + } + + static void GL_ReleaseContext(const SGLContext &Context) + { + Class NSOpenGLContextClass = (Class) objc_getClass("NSOpenGLContext"); + SEL selector = sel_registerName("clearCurrentContext"); + objc_msgSend((objc_object*) NSOpenGLContextClass, selector); + } + + static void GL_SwapBuffers(const SGLContext &Context) + { + SEL selector = sel_registerName("flushBuffer"); + objc_msgSend(Context.m_Context, selector); + } + + class CAutoreleasePool + { + private: + id m_Pool; + + public: + CAutoreleasePool() + { + Class NSAutoreleasePoolClass = (Class) objc_getClass("NSAutoreleasePool"); + m_Pool = class_createInstance(NSAutoreleasePoolClass, 0); + SEL selector = sel_registerName("init"); + objc_msgSend(m_Pool, selector); + } + + ~CAutoreleasePool() + { + SEL selector = sel_registerName("drain"); + objc_msgSend(m_Pool, selector); + } + }; + +#elif defined(CONF_FAMILY_UNIX) + + #include + + struct SGLContext + { + Display *m_pDisplay; + GLXDrawable m_Drawable; + GLXContext m_Context; + }; + + static SGLContext GL_GetCurrentContext() + { + SGLContext Context; + Context.m_pDisplay = glXGetCurrentDisplay(); + Context.m_Drawable = glXGetCurrentDrawable(); + Context.m_Context = glXGetCurrentContext(); + return Context; + } + + static void GL_MakeCurrent(const SGLContext &Context) { glXMakeCurrent(Context.m_pDisplay, Context.m_Drawable, Context.m_Context); } + static void GL_ReleaseContext(const SGLContext &Context) { glXMakeCurrent(Context.m_pDisplay, None, 0x0); } + static void GL_SwapBuffers(const SGLContext &Context) { glXSwapBuffers(Context.m_pDisplay, Context.m_Drawable); } +#else + #error missing implementation +#endif + + +// basic threaded backend, abstract, missing init and shutdown functions +class CGraphicsBackend_Threaded : public IGraphicsBackend +{ +public: + // constructed on the main thread, the rest of the functions is runned on the render thread + class ICommandProcessor + { + public: + virtual ~ICommandProcessor() {} + virtual void RunBuffer(CCommandBuffer *pBuffer) = 0; + }; + + CGraphicsBackend_Threaded(); + + virtual void RunBuffer(CCommandBuffer *pBuffer); + virtual bool IsIdle() const; + virtual void WaitForIdle(); + +protected: + void StartProcessor(ICommandProcessor *pProcessor); + void StopProcessor(); + +private: + ICommandProcessor *m_pProcessor; + CCommandBuffer * volatile m_pBuffer; + volatile bool m_Shutdown; + semaphore m_Activity; + semaphore m_BufferDone; + void *m_pThread; + + static void ThreadFunc(void *pUser); +}; + +// takes care of implementation independent operations +class CCommandProcessorFragment_General +{ + void Cmd_Nop(); + void Cmd_Signal(const CCommandBuffer::SCommand_Signal *pCommand); +public: + bool RunCommand(const CCommandBuffer::SCommand * pBaseCommand); +}; + +// takes care of opengl related rendering +class CCommandProcessorFragment_OpenGL +{ + struct CTexture + { + GLuint m_Tex; + int m_MemSize; + }; + CTexture m_aTextures[CCommandBuffer::MAX_TEXTURES]; + volatile int *m_pTextureMemoryUsage; + +public: + enum + { + CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_OPENGL, + }; + + struct SCommand_Init : public CCommandBuffer::SCommand + { + SCommand_Init() : SCommand(CMD_INIT) {} + volatile int *m_pTextureMemoryUsage; + }; + +private: + static int TexFormatToOpenGLFormat(int TexFormat); + static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp); + static void *Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData); + + void SetState(const CCommandBuffer::SState &State); + + void Cmd_Init(const SCommand_Init *pCommand); + void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand); + void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand); + void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand); + void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand); + void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand); + void Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand); + +public: + CCommandProcessorFragment_OpenGL(); + + bool RunCommand(const CCommandBuffer::SCommand * pBaseCommand); +}; + +// takes care of sdl related commands +class CCommandProcessorFragment_SDL +{ + // SDL stuff + SGLContext m_GLContext; +public: + enum + { + CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_SDL, + CMD_SHUTDOWN, + }; + + struct SCommand_Init : public CCommandBuffer::SCommand + { + SCommand_Init() : SCommand(CMD_INIT) {} + SGLContext m_Context; + }; + + struct SCommand_Shutdown : public CCommandBuffer::SCommand + { + SCommand_Shutdown() : SCommand(CMD_SHUTDOWN) {} + }; + +private: + void Cmd_Init(const SCommand_Init *pCommand); + void Cmd_Shutdown(const SCommand_Shutdown *pCommand); + void Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand); + void Cmd_VideoModes(const CCommandBuffer::SCommand_VideoModes *pCommand); +public: + CCommandProcessorFragment_SDL(); + + bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand); +}; + +// command processor impelementation, uses the fragments to combine into one processor +class CCommandProcessor_SDL_OpenGL : public CGraphicsBackend_Threaded::ICommandProcessor +{ + CCommandProcessorFragment_OpenGL m_OpenGL; + CCommandProcessorFragment_SDL m_SDL; + CCommandProcessorFragment_General m_General; + public: + virtual void RunBuffer(CCommandBuffer *pBuffer); +}; + +// graphics backend implemented with SDL and OpenGL +class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded +{ + SDL_Surface *m_pScreenSurface; + ICommandProcessor *m_pProcessor; + SGLContext m_GLContext; + volatile int m_TextureMemoryUsage; +public: + virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags); + virtual int Shutdown(); + + virtual int MemoryUsage() const; + + virtual void Minimize(); + virtual void Maximize(); + virtual int WindowActive(); + virtual int WindowOpen(); +}; diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/client.cpp teeworlds-0.6.2+dfsg/src/engine/client/client.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/client.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/client.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -35,6 +35,8 @@ #include #include +#include + #include #include @@ -48,6 +50,10 @@ #include #endif +#include "SDL.h" +#ifdef main +#undef main +#endif void CGraph::Init(float Min, float Max) { @@ -130,14 +136,16 @@ pGraphics->LinesEnd(); pGraphics->TextureSet(Font); - pGraphics->QuadsText(x+2, y+h-16, 16, 1,1,1,1, pDescription); + pGraphics->QuadsBegin(); + pGraphics->QuadsText(x+2, y+h-16, 16, pDescription); char aBuf[32]; str_format(aBuf, sizeof(aBuf), "%.2f", m_Max); - pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+2, 16, 1,1,1,1, aBuf); + pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+2, 16, aBuf); str_format(aBuf, sizeof(aBuf), "%.2f", m_Min); - pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+h-16, 16, 1,1,1,1, aBuf); + pGraphics->QuadsText(x+w-8*str_length(aBuf)-8, y+h-16, 16, aBuf); + pGraphics->QuadsEnd(); } @@ -243,10 +251,11 @@ m_pMap = 0; m_pConsole = 0; - m_FrameTime = 0.0001f; - m_FrameTimeLow = 1.0f; - m_FrameTimeHigh = 0.0f; - m_Frames = 0; + m_RenderFrameTime = 0.0001f; + m_RenderFrameTimeLow = 1.0f; + m_RenderFrameTimeHigh = 0.0f; + m_RenderFrames = 0; + m_LastRenderTime = time_get(); m_GameTickSpeed = SERVER_TICK_SPEED; @@ -455,6 +464,9 @@ // ------ state handling ----- void CClient::SetState(int s) { + if(m_State == IClient::STATE_QUITING) + return; + int Old = m_State; if(g_Config.m_Debug) { @@ -546,6 +558,7 @@ // m_RconAuthed = 0; + m_UseTempRconCommands = 0; m_pConsole->DeregisterTempAll(); m_NetClient.Disconnect(pReason); SetState(IClient::STATE_OFFLINE); @@ -666,6 +679,7 @@ //m_pGraphics->BlendNormal(); Graphics()->TextureSet(m_DebugFont); Graphics()->MapScreen(0,0,Graphics()->ScreenWidth(),Graphics()->ScreenHeight()); + Graphics()->QuadsBegin(); if(time_get()-LastSnap > time_freq()) { @@ -680,14 +694,14 @@ udp = 8 total = 42 */ - FrameTimeAvg = FrameTimeAvg*0.9f + m_FrameTime*0.1f; + FrameTimeAvg = FrameTimeAvg*0.9f + m_RenderFrameTime*0.1f; str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d", m_CurGameTick, m_PredTick, mem_stats()->allocated/1024, mem_stats()->total_allocations, Graphics()->MemoryUsage()/1024, - (int)(1.0f/FrameTimeAvg)); - Graphics()->QuadsText(2, 2, 16, 1,1,1,1, aBuffer); + (int)(1.0f/FrameTimeAvg + 0.5f)); + Graphics()->QuadsText(2, 2, 16, aBuffer); { @@ -703,7 +717,7 @@ str_format(aBuffer, sizeof(aBuffer), "send: %3d %5d+%4d=%5d (%3d kbps) avg: %5d\nrecv: %3d %5d+%4d=%5d (%3d kbps) avg: %5d", SendPackets, SendBytes, SendPackets*42, SendTotal, (SendTotal*8)/1024, SendBytes/SendPackets, RecvPackets, RecvBytes, RecvPackets*42, RecvTotal, (RecvTotal*8)/1024, RecvBytes/RecvPackets); - Graphics()->QuadsText(2, 14, 16, 1,1,1,1, aBuffer); + Graphics()->QuadsText(2, 14, 16, aBuffer); } // render rates @@ -716,7 +730,7 @@ { str_format(aBuffer, sizeof(aBuffer), "%4d %20s: %8d %8d %8d", i, GameClient()->GetItemName(i), m_SnapshotDelta.GetDataRate(i)/8, m_SnapshotDelta.GetDataUpdates(i), (m_SnapshotDelta.GetDataRate(i)/m_SnapshotDelta.GetDataUpdates(i))/8); - Graphics()->QuadsText(2, 100+y*12, 16, 1,1,1,1, aBuffer); + Graphics()->QuadsText(2, 100+y*12, 16, aBuffer); y++; } } @@ -724,7 +738,8 @@ str_format(aBuffer, sizeof(aBuffer), "pred: %d ms", (int)((m_PredictedTime.Get(Now)-m_GameTime.Get(Now))*1000/(float)time_freq())); - Graphics()->QuadsText(2, 70, 16, 1,1,1,1, aBuffer); + Graphics()->QuadsText(2, 70, 16, aBuffer); + Graphics()->QuadsEnd(); // render graphs if(g_Config.m_DbgGraphs) @@ -849,23 +864,26 @@ if(m_VersionInfo.m_State == CVersionInfo::STATE_READY && net_addr_comp(&pPacket->m_Address, &m_VersionInfo.m_VersionServeraddr.m_Addr) == 0) { // version info - if(pPacket->m_DataSize == (int)(sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)) && + if(pPacket->m_DataSize == (int)(sizeof(VERSIONSRV_VERSION) + sizeof(GAME_RELEASE_VERSION)) && mem_comp(pPacket->m_pData, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)) == 0) { - unsigned char *pVersionData = (unsigned char*)pPacket->m_pData + sizeof(VERSIONSRV_VERSION); - int VersionMatch = !mem_comp(pVersionData, VERSION_DATA, sizeof(VERSION_DATA)); + char *pVersionData = (char*)pPacket->m_pData + sizeof(VERSIONSRV_VERSION); + int VersionMatch = !mem_comp(pVersionData, GAME_RELEASE_VERSION, sizeof(GAME_RELEASE_VERSION)); + + char aVersion[sizeof(GAME_RELEASE_VERSION)]; + str_copy(aVersion, pVersionData, sizeof(aVersion)); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "version does %s (%d.%d.%d)", + str_format(aBuf, sizeof(aBuf), "version does %s (%s)", VersionMatch ? "match" : "NOT match", - pVersionData[1], pVersionData[2], pVersionData[3]); + aVersion); m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/version", aBuf); // assume version is out of date when version-data doesn't match - if (!VersionMatch) + if(!VersionMatch) { - str_format(m_aVersionStr, sizeof(m_aVersionStr), "%d.%d.%d", pVersionData[1], pVersionData[2], pVersionData[3]); + str_copy(m_aVersionStr, aVersion, sizeof(m_aVersionStr)); } // request the map version list now @@ -964,7 +982,7 @@ Info.m_NumPlayers < 0 || Info.m_NumPlayers > Info.m_NumClients || Info.m_MaxPlayers < 0 || Info.m_MaxPlayers > Info.m_MaxClients) return; - net_addr_str(&pPacket->m_Address, Info.m_aAddress, sizeof(Info.m_aAddress)); + net_addr_str(&pPacket->m_Address, Info.m_aAddress, sizeof(Info.m_aAddress), true); for(int i = 0; i < Info.m_NumClients; i++) { @@ -1153,9 +1171,12 @@ int Result = Unpacker.GetInt(); if(Unpacker.Error() == 0) m_RconAuthed = Result; + int Old = m_UseTempRconCommands; m_UseTempRconCommands = Unpacker.GetInt(); if(Unpacker.Error() != 0) m_UseTempRconCommands = 0; + if(Old != 0 && m_UseTempRconCommands == 0) + m_pConsole->DeregisterTempAll(); } else if(Msg == NETMSG_RCON_LINE) { @@ -1292,7 +1313,6 @@ } // unpack delta - PurgeTick = DeltaTick; SnapSize = m_SnapshotDelta.UnpackDelta(pDeltaShot, pTmpBuffer3, pDeltaData, DeltaSize); if(SnapSize < 0) { @@ -1331,7 +1351,7 @@ if(m_aSnapshots[SNAP_PREV] && m_aSnapshots[SNAP_PREV]->m_Tick < PurgeTick) PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick; if(m_aSnapshots[SNAP_CURRENT] && m_aSnapshots[SNAP_CURRENT]->m_Tick < PurgeTick) - PurgeTick = m_aSnapshots[SNAP_PREV]->m_Tick; + PurgeTick = m_aSnapshots[SNAP_CURRENT]->m_Tick; m_SnapshotStorage.PurgeUntil(PurgeTick); // add new @@ -1675,7 +1695,7 @@ // fetch interfaces m_pEngine = Kernel()->RequestInterface(); m_pEditor = Kernel()->RequestInterface(); - m_pGraphics = Kernel()->RequestInterface(); + //m_pGraphics = Kernel()->RequestInterface(); m_pSound = Kernel()->RequestInterface(); m_pGameClient = Kernel()->RequestInterface(); m_pInput = Kernel()->RequestInterface(); @@ -1690,24 +1710,57 @@ void CClient::Run() { - int64 ReportTime = time_get(); - int64 ReportInterval = time_freq()*1; - m_LocalStartTime = time_get(); m_SnapshotParts = 0; + // init SDL + { + if(SDL_Init(0) < 0) + { + dbg_msg("client", "unable to init SDL base: %s", SDL_GetError()); + return; + } + + atexit(SDL_Quit); // ignore_convention + } + // init graphics - if(m_pGraphics->Init() != 0) - return; + { + if(g_Config.m_GfxThreaded) + m_pGraphics = CreateEngineGraphicsThreaded(); + else + m_pGraphics = CreateEngineGraphics(); + + bool RegisterFail = false; + RegisterFail = RegisterFail || !Kernel()->RegisterInterface(static_cast(m_pGraphics)); // register graphics as both + RegisterFail = RegisterFail || !Kernel()->RegisterInterface(static_cast(m_pGraphics)); + + if(RegisterFail || m_pGraphics->Init() != 0) + { + dbg_msg("client", "couldn't init graphics"); + return; + } + } + + // init sound, allowed to fail + m_SoundInitFailed = Sound()->Init() != 0; // open socket { NETADDR BindAddr; - mem_zero(&BindAddr, sizeof(BindAddr)); - BindAddr.type = NETTYPE_ALL; + if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0) + { + // got bindaddr + BindAddr.type = NETTYPE_ALL; + } + else + { + mem_zero(&BindAddr, sizeof(BindAddr)); + BindAddr.type = NETTYPE_ALL; + } if(!m_NetClient.Open(BindAddr, 0)) { - dbg_msg("client", "couldn't start network"); + dbg_msg("client", "couldn't open socket"); return; } } @@ -1724,14 +1777,13 @@ // init the editor m_pEditor->Init(); - // init sound, allowed to fail - m_SoundInitFailed = Sound()->Init() != 0; // load data if(!LoadData()) return; GameClient()->OnInit(); + char aBuf[256]; str_format(aBuf, sizeof(aBuf), "version %s", GameClient()->NetVersion()); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); @@ -1756,9 +1808,6 @@ while (1) { - int64 FrameStartTime = time_get(); - m_Frames++; - // VersionUpdate(); @@ -1808,7 +1857,10 @@ // panic quit button if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyPressed(KEY_LSHIFT) && Input()->KeyPressed('q')) + { + Quit(); break; + } if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyPressed(KEY_LSHIFT) && Input()->KeyDown('d')) g_Config.m_Debug ^= 1; @@ -1828,39 +1880,61 @@ */ // render - if(g_Config.m_ClEditor) { - if(!m_EditorActive) + if(g_Config.m_ClEditor) { - GameClient()->OnActivateEditor(); - m_EditorActive = true; + if(!m_EditorActive) + { + GameClient()->OnActivateEditor(); + m_EditorActive = true; + } } - - Update(); - m_pEditor->UpdateAndRender(); - DebugRender(); - m_pGraphics->Swap(); - } - else - { - if(m_EditorActive) + else if(m_EditorActive) m_EditorActive = false; Update(); - - if(g_Config.m_DbgStress) + + if(!g_Config.m_GfxAsyncRender || m_pGraphics->IsIdle()) { - if((m_Frames%10) == 0) + m_RenderFrames++; + + // update frametime + int64 Now = time_get(); + m_RenderFrameTime = (Now - m_LastRenderTime) / (float)time_freq(); + if(m_RenderFrameTime < m_RenderFrameTimeLow) + m_RenderFrameTimeLow = m_RenderFrameTime; + if(m_RenderFrameTime > m_RenderFrameTimeHigh) + m_RenderFrameTimeHigh = m_RenderFrameTime; + m_FpsGraph.Add(1.0f/m_RenderFrameTime, 1,1,1); + + m_LastRenderTime = Now; + + if(g_Config.m_DbgStress) { - Render(); + if((m_RenderFrames%10) == 0) + { + if(!m_EditorActive) + Render(); + else + { + m_pEditor->UpdateAndRender(); + DebugRender(); + } + m_pGraphics->Swap(); + } + } + else + { + if(!m_EditorActive) + Render(); + else + { + m_pEditor->UpdateAndRender(); + DebugRender(); + } m_pGraphics->Swap(); } } - else - { - Render(); - m_pGraphics->Swap(); - } } AutoScreenshot_Cleanup(); @@ -1870,10 +1944,10 @@ break; // beNice - if(g_Config.m_DbgStress) + if(g_Config.m_ClCpuThrottle) + thread_sleep(g_Config.m_ClCpuThrottle); + else if(g_Config.m_DbgStress || !m_pGraphics->WindowActive()) thread_sleep(5); - else if(g_Config.m_ClCpuThrottle || !m_pGraphics->WindowActive()) - thread_sleep(1); if(g_Config.m_DbgHitch) { @@ -1881,32 +1955,25 @@ g_Config.m_DbgHitch = 0; } + /* if(ReportTime < time_get()) { if(0 && g_Config.m_Debug) { dbg_msg("client/report", "fps=%.02f (%.02f %.02f) netstate=%d", m_Frames/(float)(ReportInterval/time_freq()), - 1.0f/m_FrameTimeHigh, - 1.0f/m_FrameTimeLow, + 1.0f/m_RenderFrameTimeHigh, + 1.0f/m_RenderFrameTimeLow, m_NetClient.State()); } - m_FrameTimeLow = 1; - m_FrameTimeHigh = 0; - m_Frames = 0; + m_RenderFrameTimeLow = 1; + m_RenderFrameTimeHigh = 0; + m_RenderFrames = 0; ReportTime += ReportInterval; - } - - // update frametime - m_FrameTime = (time_get()-FrameStartTime)/(float)time_freq(); - if(m_FrameTime < m_FrameTimeLow) - m_FrameTimeLow = m_FrameTime; - if(m_FrameTime > m_FrameTimeHigh) - m_FrameTimeHigh = m_FrameTime; + }*/ + // update local time m_LocalTime = (time_get()-m_LocalStartTime)/(float)time_freq(); - - m_FpsGraph.Add(1.0f/m_FrameTime, 1,1,1); } GameClient()->OnShutdown(); @@ -1914,6 +1981,11 @@ m_pGraphics->Shutdown(); m_pSound->Shutdown(); + + // shutdown SDL + { + SDL_Quit(); + } } @@ -2104,6 +2176,11 @@ m_DemoRecorder.Stop(); } +void CClient::DemoRecorder_AddDemoMarker() +{ + m_DemoRecorder.AddDemoMarker(); +} + void CClient::Con_Record(IConsole::IResult *pResult, void *pUserData) { CClient *pSelf = (CClient *)pUserData; @@ -2119,6 +2196,12 @@ pSelf->DemoRecorder_Stop(); } +void CClient::Con_AddDemoMarker(IConsole::IResult *pResult, void *pUserData) +{ + CClient *pSelf = (CClient *)pUserData; + pSelf->DemoRecorder_AddDemoMarker(); +} + void CClient::ServerBrowserUpdate() { m_ResortServerBrowser = true; @@ -2154,9 +2237,10 @@ m_pConsole->Register("screenshot", "", CFGFLAG_CLIENT, Con_Screenshot, this, "Take a screenshot"); m_pConsole->Register("rcon", "r", CFGFLAG_CLIENT, Con_Rcon, this, "Send specified command to rcon"); m_pConsole->Register("rcon_auth", "s", CFGFLAG_CLIENT, Con_RconAuth, this, "Authenticate to rcon"); - m_pConsole->Register("play", "r", CFGFLAG_CLIENT, Con_Play, this, "Play the file specified"); + m_pConsole->Register("play", "r", CFGFLAG_CLIENT|CFGFLAG_STORE, Con_Play, this, "Play the file specified"); m_pConsole->Register("record", "?s", CFGFLAG_CLIENT, Con_Record, this, "Record to the file"); m_pConsole->Register("stoprecord", "", CFGFLAG_CLIENT, Con_StopRecord, this, "Stop recording"); + m_pConsole->Register("add_demomarker", "", CFGFLAG_CLIENT, Con_AddDemoMarker, this, "Add demo timeline marker"); m_pConsole->Register("add_favorite", "s", CFGFLAG_CLIENT, Con_AddFavorite, this, "Add a server as a favorite"); m_pConsole->Register("remove_favorite", "s", CFGFLAG_CLIENT, Con_RemoveFavorite, this, "Remove a server from favorites"); @@ -2186,11 +2270,13 @@ */ #if defined(CONF_PLATFORM_MACOSX) -extern "C" int SDL_main(int argc, const char **argv) // ignore_convention +extern "C" int SDL_main(int argc, char **argv_) // ignore_convention +{ + const char **argv = const_cast(argv_); #else int main(int argc, const char **argv) // ignore_convention -#endif { +#endif #if defined(CONF_FAMILY_WINDOWS) for(int i = 1; i < argc; i++) // ignore_convention { @@ -2210,9 +2296,8 @@ // create the components IEngine *pEngine = CreateEngine("Teeworlds"); IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT); - IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention + IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_CLIENT, argc, argv); // ignore_convention IConfig *pConfig = CreateConfig(); - IEngineGraphics *pEngineGraphics = CreateEngineGraphics(); IEngineSound *pEngineSound = CreateEngineSound(); IEngineInput *pEngineInput = CreateEngineInput(); IEngineTextRender *pEngineTextRender = CreateEngineTextRender(); @@ -2226,9 +2311,6 @@ RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfig); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineGraphics)); // register graphics as both - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineGraphics)); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineSound)); // register as both RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineSound)); diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/client.h teeworlds-0.6.2+dfsg/src/engine/client/client.h --- teeworlds-0.6.1+dfsg/src/engine/client/client.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/client.h 2013-05-01 11:47:39.000000000 +0000 @@ -84,9 +84,12 @@ int64 m_LocalStartTime; int m_DebugFont; - float m_FrameTimeLow; - float m_FrameTimeHigh; - int m_Frames; + + int64 m_LastRenderTime; + float m_RenderFrameTimeLow; + float m_RenderFrameTimeHigh; + int m_RenderFrames; + NETADDR m_ServerAddress; int m_WindowMustRefocus; int m_SnapCrcErrors; @@ -172,6 +175,10 @@ class CHostLookup m_VersionServeraddr; } m_VersionInfo; + volatile int m_GfxState; + static void GraphicsThreadProxy(void *pThis) { ((CClient*)pThis)->GraphicsThread(); } + void GraphicsThread(); + public: IEngine *Engine() { return m_pEngine; } IEngineGraphics *Graphics() { return m_pGraphics; } @@ -280,6 +287,7 @@ static void Con_Play(IConsole::IResult *pResult, void *pUserData); static void Con_Record(IConsole::IResult *pResult, void *pUserData); static void Con_StopRecord(IConsole::IResult *pResult, void *pUserData); + static void Con_AddDemoMarker(IConsole::IResult *pResult, void *pUserData); static void ConchainServerBrowserUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); void RegisterCommands(); @@ -288,6 +296,7 @@ void DemoRecorder_Start(const char *pFilename, bool WithTimestamp); void DemoRecorder_HandleAutoStart(); void DemoRecorder_Stop(); + void DemoRecorder_AddDemoMarker(); void AutoScreenshot_Start(); void AutoScreenshot_Cleanup(); diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/graphics.cpp teeworlds-0.6.2+dfsg/src/engine/client/graphics.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/graphics.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/graphics.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -3,21 +3,10 @@ #include #include +#include #include "SDL.h" - -#ifdef CONF_FAMILY_WINDOWS - #define WIN32_LEAN_AND_MEAN - #include -#endif - -#ifdef CONF_PLATFORM_MACOSX - #include - #include -#else - #include - #include -#endif +#include "SDL_opengl.h" #include #include @@ -32,12 +21,19 @@ #include "graphics.h" -// compressed textures -#define GL_COMPRESSED_RGB_ARB 0x84ED -#define GL_COMPRESSED_RGBA_ARB 0x84EE -#define GL_COMPRESSED_ALPHA_ARB 0x84E9 -#define TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#if defined(CONF_PLATFORM_MACOSX) + + class semaphore + { + SDL_sem *sem; + public: + semaphore() { sem = SDL_CreateSemaphore(0); } + ~semaphore() { SDL_DestroySemaphore(sem); } + void wait() { SDL_SemWait(sem); } + void signal() { SDL_SemPost(sem); } + }; +#endif static CVideoMode g_aFakeModes[] = { @@ -216,6 +212,18 @@ glBlendFunc(GL_SRC_ALPHA, GL_ONE); } +void CGraphics_OpenGL::WrapNormal() +{ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); +} + +void CGraphics_OpenGL::WrapClamp() +{ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +} + int CGraphics_OpenGL::MemoryUsage() const { return m_TextureMemoryUsage; @@ -289,6 +297,18 @@ return 0; } +int CGraphics_OpenGL::LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData) +{ + int Oglformat = GL_RGBA; + if(Format == CImageInfo::FORMAT_RGB) + Oglformat = GL_RGB; + else if(Format == CImageInfo::FORMAT_ALPHA) + Oglformat = GL_ALPHA; + + glBindTexture(GL_TEXTURE_2D, m_aTextures[TextureID].m_Tex); + glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pData); + return 0; +} int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) { @@ -355,9 +375,19 @@ glGenTextures(1, &m_aTextures[Tex].m_Tex); glBindTexture(GL_TEXTURE_2D, m_aTextures[Tex].m_Tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pTexData); + + if(Flags&TEXLOAD_NOMIPMAPS) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pData); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pTexData); + } // calculate memory usage { @@ -400,6 +430,8 @@ ID = LoadTextureRaw(Img.m_Width, Img.m_Height, Img.m_Format, Img.m_pData, StoreFormat, Flags); mem_free(Img.m_pData); + if(ID != m_InvalidTexture && g_Config.m_Debug) + dbg_msg("graphics/texture", "loaded %s", pFilename); return ID; } @@ -668,13 +700,10 @@ AddVertices(4*Num); } -void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) +void CGraphics_OpenGL::QuadsText(float x, float y, float Size, const char *pText) { float StartX = x; - QuadsBegin(); - SetColor(r,g,b,a); - while(*pText) { char c = *pText; @@ -698,11 +727,9 @@ x += Size/2; } } - - QuadsEnd(); } -bool CGraphics_OpenGL::Init() +int CGraphics_OpenGL::Init() { m_pStorage = Kernel()->RequestInterface(); m_pConsole = Kernel()->RequestInterface(); @@ -738,24 +765,26 @@ m_InvalidTexture = LoadTextureRaw(4,4,CImageInfo::FORMAT_RGBA,aNullTextureData,CImageInfo::FORMAT_RGBA,TEXLOAD_NORESAMPLE); - return true; + return 0; } int CGraphics_SDL::TryInit() { - const SDL_VideoInfo *pInfo; - int Flags = SDL_OPENGL; + const SDL_VideoInfo *pInfo = SDL_GetVideoInfo(); + SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); // prevent stuck mouse cursor sdl-bug when loosing fullscreen focus in windows + + // use current resolution as default + if(g_Config.m_GfxScreenWidth == 0 || g_Config.m_GfxScreenHeight == 0) + { + g_Config.m_GfxScreenWidth = pInfo->current_w; + g_Config.m_GfxScreenHeight = pInfo->current_h; + } m_ScreenWidth = g_Config.m_GfxScreenWidth; m_ScreenHeight = g_Config.m_GfxScreenHeight; - pInfo = SDL_GetVideoInfo(); - SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); - // set flags - Flags = SDL_OPENGL; - Flags |= SDL_GL_DOUBLEBUFFER; - Flags |= SDL_HWPALETTE; + int Flags = SDL_OPENGL; if(g_Config.m_DbgResizable) Flags |= SDL_RESIZABLE; @@ -767,7 +796,15 @@ if(pInfo->blit_hw) // ignore_convention Flags |= SDL_HWACCEL; - if(g_Config.m_GfxFullscreen) + if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen) + { + dbg_msg("gfx", "both borderless and fullscreen activated, disabling borderless"); + g_Config.m_GfxBorderless = 0; + } + + if(g_Config.m_GfxBorderless) + Flags |= SDL_NOFRAME; + else if(g_Config.m_GfxFullscreen) Flags |= SDL_FULLSCREEN; // set gl attributes @@ -841,7 +878,7 @@ m_pScreenSurface = 0; } -bool CGraphics_SDL::Init() +int CGraphics_SDL::Init() { { int Systems = SDL_INIT_VIDEO; @@ -855,7 +892,7 @@ if(SDL_Init(Systems) < 0) { dbg_msg("gfx", "unable to init SDL: %s", SDL_GetError()); - return true; + return -1; } } @@ -863,18 +900,18 @@ #ifdef CONF_FAMILY_WINDOWS if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) // ignore_convention - putenv("SDL_VIDEO_WINDOW_POS=8,27"); // ignore_convention + putenv("SDL_VIDEO_WINDOW_POS=center"); // ignore_convention #endif if(InitWindow() != 0) - return true; + return -1; SDL_ShowCursor(0); CGraphics_OpenGL::Init(); MapScreen(0,0,g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight); - return false; + return 0; } void CGraphics_SDL::Shutdown() @@ -916,7 +953,8 @@ { if(m_DoScreenshot) { - ScreenshotDirect(m_aScreenshotName); + if(WindowActive()) + ScreenshotDirect(m_aScreenshotName); m_DoScreenshot = false; } @@ -972,4 +1010,19 @@ return NumModes; } +// syncronization +void CGraphics_SDL::InsertSignal(semaphore *pSemaphore) +{ + pSemaphore->signal(); +} + +bool CGraphics_SDL::IsIdle() +{ + return true; +} + +void CGraphics_SDL::WaitForIdle() +{ +} + extern IEngineGraphics *CreateEngineGraphics() { return new CGraphics_SDL(); } diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/graphics.h teeworlds-0.6.2+dfsg/src/engine/client/graphics.h --- teeworlds-0.6.1+dfsg/src/engine/client/graphics.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/graphics.h 2013-05-01 11:47:39.000000000 +0000 @@ -78,6 +78,9 @@ virtual void BlendNormal(); virtual void BlendAdditive(); + virtual void WrapNormal(); + virtual void WrapClamp(); + virtual int MemoryUsage() const; virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY); @@ -89,6 +92,7 @@ virtual int UnloadTexture(int Index); virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags); + virtual int LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData); // simple uncompressed RGBA loaders virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags); @@ -115,9 +119,9 @@ virtual void QuadsDraw(CQuadItem *pArray, int Num); virtual void QuadsDrawTL(const CQuadItem *pArray, int Num); virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num); - virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText); + virtual void QuadsText(float x, float y, float Size, const char *pText); - virtual bool Init(); + virtual int Init(); }; class CGraphics_SDL : public CGraphics_OpenGL @@ -129,7 +133,7 @@ public: CGraphics_SDL(); - virtual bool Init(); + virtual int Init(); virtual void Shutdown(); virtual void Minimize(); @@ -143,6 +147,10 @@ virtual int GetVideoModes(CVideoMode *pModes, int MaxModes); + // syncronization + virtual void InsertSignal(semaphore *pSemaphore); + virtual bool IsIdle(); + virtual void WaitForIdle(); }; #endif diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/graphics_threaded.cpp teeworlds-0.6.2+dfsg/src/engine/client/graphics_threaded.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/graphics_threaded.cpp 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/graphics_threaded.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,881 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include // cosf, sinf + +#include "graphics_threaded.h" + +static CVideoMode g_aFakeModes[] = { + {320,240,8,8,8}, {400,300,8,8,8}, {640,480,8,8,8}, + {720,400,8,8,8}, {768,576,8,8,8}, {800,600,8,8,8}, + {1024,600,8,8,8}, {1024,768,8,8,8}, {1152,864,8,8,8}, + {1280,768,8,8,8}, {1280,800,8,8,8}, {1280,960,8,8,8}, + {1280,1024,8,8,8}, {1368,768,8,8,8}, {1400,1050,8,8,8}, + {1440,900,8,8,8}, {1440,1050,8,8,8}, {1600,1000,8,8,8}, + {1600,1200,8,8,8}, {1680,1050,8,8,8}, {1792,1344,8,8,8}, + {1800,1440,8,8,8}, {1856,1392,8,8,8}, {1920,1080,8,8,8}, + {1920,1200,8,8,8}, {1920,1440,8,8,8}, {1920,2400,8,8,8}, + {2048,1536,8,8,8}, + + {320,240,5,6,5}, {400,300,5,6,5}, {640,480,5,6,5}, + {720,400,5,6,5}, {768,576,5,6,5}, {800,600,5,6,5}, + {1024,600,5,6,5}, {1024,768,5,6,5}, {1152,864,5,6,5}, + {1280,768,5,6,5}, {1280,800,5,6,5}, {1280,960,5,6,5}, + {1280,1024,5,6,5}, {1368,768,5,6,5}, {1400,1050,5,6,5}, + {1440,900,5,6,5}, {1440,1050,5,6,5}, {1600,1000,5,6,5}, + {1600,1200,5,6,5}, {1680,1050,5,6,5}, {1792,1344,5,6,5}, + {1800,1440,5,6,5}, {1856,1392,5,6,5}, {1920,1080,5,6,5}, + {1920,1200,5,6,5}, {1920,1440,5,6,5}, {1920,2400,5,6,5}, + {2048,1536,5,6,5} +}; + +void CGraphics_Threaded::FlushVertices() +{ + if(m_NumVertices == 0) + return; + + int NumVerts = m_NumVertices; + m_NumVertices = 0; + + CCommandBuffer::SCommand_Render Cmd; + Cmd.m_State = m_State; + + if(m_Drawing == DRAWING_QUADS) + { + Cmd.m_PrimType = CCommandBuffer::PRIMTYPE_QUADS; + Cmd.m_PrimCount = NumVerts/4; + } + else if(m_Drawing == DRAWING_LINES) + { + Cmd.m_PrimType = CCommandBuffer::PRIMTYPE_LINES; + Cmd.m_PrimCount = NumVerts/2; + } + else + return; + + Cmd.m_pVertices = (CCommandBuffer::SVertex *)m_pCommandBuffer->AllocData(sizeof(CCommandBuffer::SVertex)*NumVerts); + if(Cmd.m_pVertices == 0x0) + { + // kick command buffer and try again + KickCommandBuffer(); + + Cmd.m_pVertices = (CCommandBuffer::SVertex *)m_pCommandBuffer->AllocData(sizeof(CCommandBuffer::SVertex)*NumVerts); + if(Cmd.m_pVertices == 0x0) + { + dbg_msg("graphics", "failed to allocate data for vertices"); + return; + } + } + + // check if we have enough free memory in the commandbuffer + if(!m_pCommandBuffer->AddCommand(Cmd)) + { + // kick command buffer and try again + KickCommandBuffer(); + + Cmd.m_pVertices = (CCommandBuffer::SVertex *)m_pCommandBuffer->AllocData(sizeof(CCommandBuffer::SVertex)*NumVerts); + if(Cmd.m_pVertices == 0x0) + { + dbg_msg("graphics", "failed to allocate data for vertices"); + return; + } + + if(!m_pCommandBuffer->AddCommand(Cmd)) + { + dbg_msg("graphics", "failed to allocate memory for render command"); + return; + } + } + + mem_copy(Cmd.m_pVertices, m_aVertices, sizeof(CCommandBuffer::SVertex)*NumVerts); +} + +void CGraphics_Threaded::AddVertices(int Count) +{ + m_NumVertices += Count; + if((m_NumVertices + Count) >= MAX_VERTICES) + FlushVertices(); +} + +void CGraphics_Threaded::Rotate4(const CCommandBuffer::SPoint &rCenter, CCommandBuffer::SVertex *pPoints) +{ + float c = cosf(m_Rotation); + float s = sinf(m_Rotation); + float x, y; + int i; + + for(i = 0; i < 4; i++) + { + x = pPoints[i].m_Pos.x - rCenter.x; + y = pPoints[i].m_Pos.y - rCenter.y; + pPoints[i].m_Pos.x = x * c - y * s + rCenter.x; + pPoints[i].m_Pos.y = x * s + y * c + rCenter.y; + } +} + +CGraphics_Threaded::CGraphics_Threaded() +{ + m_State.m_ScreenTL.x = 0; + m_State.m_ScreenTL.y = 0; + m_State.m_ScreenBR.x = 0; + m_State.m_ScreenBR.y = 0; + m_State.m_ClipEnable = false; + m_State.m_ClipX = 0; + m_State.m_ClipY = 0; + m_State.m_ClipW = 0; + m_State.m_ClipH = 0; + m_State.m_Texture = -1; + m_State.m_BlendMode = CCommandBuffer::BLEND_NONE; + m_State.m_WrapMode = CCommandBuffer::WRAP_REPEAT; + + m_CurrentCommandBuffer = 0; + m_pCommandBuffer = 0x0; + m_apCommandBuffers[0] = 0x0; + m_apCommandBuffers[1] = 0x0; + + m_NumVertices = 0; + + m_ScreenWidth = -1; + m_ScreenHeight = -1; + + m_Rotation = 0; + m_Drawing = 0; + m_InvalidTexture = 0; + + m_TextureMemoryUsage = 0; + + m_RenderEnable = true; + m_DoScreenshot = false; +} + +void CGraphics_Threaded::ClipEnable(int x, int y, int w, int h) +{ + if(x < 0) + w += x; + if(y < 0) + h += y; + + x = clamp(x, 0, ScreenWidth()); + y = clamp(y, 0, ScreenHeight()); + w = clamp(w, 0, ScreenWidth()-x); + h = clamp(h, 0, ScreenHeight()-y); + + m_State.m_ClipEnable = true; + m_State.m_ClipX = x; + m_State.m_ClipY = ScreenHeight()-(y+h); + m_State.m_ClipW = w; + m_State.m_ClipH = h; +} + +void CGraphics_Threaded::ClipDisable() +{ + m_State.m_ClipEnable = false; +} + +void CGraphics_Threaded::BlendNone() +{ + m_State.m_BlendMode = CCommandBuffer::BLEND_NONE; +} + +void CGraphics_Threaded::BlendNormal() +{ + m_State.m_BlendMode = CCommandBuffer::BLEND_ALPHA; +} + +void CGraphics_Threaded::BlendAdditive() +{ + m_State.m_BlendMode = CCommandBuffer::BLEND_ADDITIVE; +} + +void CGraphics_Threaded::WrapNormal() +{ + m_State.m_WrapMode = CCommandBuffer::WRAP_REPEAT; +} + +void CGraphics_Threaded::WrapClamp() +{ + m_State.m_WrapMode = CCommandBuffer::WRAP_CLAMP; +} + +int CGraphics_Threaded::MemoryUsage() const +{ + return m_pBackend->MemoryUsage(); +} + +void CGraphics_Threaded::MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY) +{ + m_State.m_ScreenTL.x = TopLeftX; + m_State.m_ScreenTL.y = TopLeftY; + m_State.m_ScreenBR.x = BottomRightX; + m_State.m_ScreenBR.y = BottomRightY; +} + +void CGraphics_Threaded::GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY) +{ + *pTopLeftX = m_State.m_ScreenTL.x; + *pTopLeftY = m_State.m_ScreenTL.y; + *pBottomRightX = m_State.m_ScreenBR.x; + *pBottomRightY = m_State.m_ScreenBR.y; +} + +void CGraphics_Threaded::LinesBegin() +{ + dbg_assert(m_Drawing == 0, "called Graphics()->LinesBegin twice"); + m_Drawing = DRAWING_LINES; + SetColor(1,1,1,1); +} + +void CGraphics_Threaded::LinesEnd() +{ + dbg_assert(m_Drawing == DRAWING_LINES, "called Graphics()->LinesEnd without begin"); + FlushVertices(); + m_Drawing = 0; +} + +void CGraphics_Threaded::LinesDraw(const CLineItem *pArray, int Num) +{ + dbg_assert(m_Drawing == DRAWING_LINES, "called Graphics()->LinesDraw without begin"); + + for(int i = 0; i < Num; ++i) + { + m_aVertices[m_NumVertices + 2*i].m_Pos.x = pArray[i].m_X0; + m_aVertices[m_NumVertices + 2*i].m_Pos.y = pArray[i].m_Y0; + m_aVertices[m_NumVertices + 2*i].m_Tex = m_aTexture[0]; + m_aVertices[m_NumVertices + 2*i].m_Color = m_aColor[0]; + + m_aVertices[m_NumVertices + 2*i + 1].m_Pos.x = pArray[i].m_X1; + m_aVertices[m_NumVertices + 2*i + 1].m_Pos.y = pArray[i].m_Y1; + m_aVertices[m_NumVertices + 2*i + 1].m_Tex = m_aTexture[1]; + m_aVertices[m_NumVertices + 2*i + 1].m_Color = m_aColor[1]; + } + + AddVertices(2*Num); +} + +int CGraphics_Threaded::UnloadTexture(int Index) +{ + if(Index == m_InvalidTexture) + return 0; + + if(Index < 0) + return 0; + + CCommandBuffer::SCommand_Texture_Destroy Cmd; + Cmd.m_Slot = Index; + m_pCommandBuffer->AddCommand(Cmd); + + m_aTextureIndices[Index] = m_FirstFreeTexture; + m_FirstFreeTexture = Index; + return 0; +} + +static int ImageFormatToTexFormat(int Format) +{ + if(Format == CImageInfo::FORMAT_RGB) return CCommandBuffer::TEXFORMAT_RGB; + if(Format == CImageInfo::FORMAT_RGBA) return CCommandBuffer::TEXFORMAT_RGBA; + if(Format == CImageInfo::FORMAT_ALPHA) return CCommandBuffer::TEXFORMAT_ALPHA; + return CCommandBuffer::TEXFORMAT_RGBA; +} + +static int ImageFormatToPixelSize(int Format) +{ + switch(Format) + { + case CImageInfo::FORMAT_RGB: return 3; + case CImageInfo::FORMAT_ALPHA: return 1; + default: return 4; + } +} + + +int CGraphics_Threaded::LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData) +{ + CCommandBuffer::SCommand_Texture_Update Cmd; + Cmd.m_Slot = TextureID; + Cmd.m_X = x; + Cmd.m_Y = y; + Cmd.m_Width = Width; + Cmd.m_Height = Height; + Cmd.m_Format = ImageFormatToTexFormat(Format); + + // calculate memory usage + int MemSize = Width*Height*ImageFormatToPixelSize(Format); + + // copy texture data + void *pTmpData = mem_alloc(MemSize, sizeof(void*)); + mem_copy(pTmpData, pData, MemSize); + Cmd.m_pData = pTmpData; + + // + m_pCommandBuffer->AddCommand(Cmd); + return 0; +} + +int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) +{ + // don't waste memory on texture if we are stress testing + if(g_Config.m_DbgStress) + return m_InvalidTexture; + + // grab texture + int Tex = m_FirstFreeTexture; + m_FirstFreeTexture = m_aTextureIndices[Tex]; + m_aTextureIndices[Tex] = -1; + + CCommandBuffer::SCommand_Texture_Create Cmd; + Cmd.m_Slot = Tex; + Cmd.m_Width = Width; + Cmd.m_Height = Height; + Cmd.m_PixelSize = ImageFormatToPixelSize(Format); + Cmd.m_Format = ImageFormatToTexFormat(Format); + Cmd.m_StoreFormat = ImageFormatToTexFormat(StoreFormat); + + // flags + Cmd.m_Flags = 0; + if(Flags&IGraphics::TEXLOAD_NOMIPMAPS) + Cmd.m_Flags |= CCommandBuffer::TEXFLAG_NOMIPMAPS; + if(g_Config.m_GfxTextureCompression) + Cmd.m_Flags |= CCommandBuffer::TEXFLAG_COMPRESSED; + if(g_Config.m_GfxTextureQuality || Flags&TEXLOAD_NORESAMPLE) + Cmd.m_Flags |= CCommandBuffer::TEXFLAG_QUALITY; + + // copy texture data + int MemSize = Width*Height*Cmd.m_PixelSize; + void *pTmpData = mem_alloc(MemSize, sizeof(void*)); + mem_copy(pTmpData, pData, MemSize); + Cmd.m_pData = pTmpData; + + // + m_pCommandBuffer->AddCommand(Cmd); + + return Tex; +} + +// simple uncompressed RGBA loaders +int CGraphics_Threaded::LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) +{ + int l = str_length(pFilename); + int ID; + CImageInfo Img; + + if(l < 3) + return -1; + if(LoadPNG(&Img, pFilename, StorageType)) + { + if (StoreFormat == CImageInfo::FORMAT_AUTO) + StoreFormat = Img.m_Format; + + ID = LoadTextureRaw(Img.m_Width, Img.m_Height, Img.m_Format, Img.m_pData, StoreFormat, Flags); + mem_free(Img.m_pData); + if(ID != m_InvalidTexture && g_Config.m_Debug) + dbg_msg("graphics/texture", "loaded %s", pFilename); + return ID; + } + + return m_InvalidTexture; +} + +int CGraphics_Threaded::LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) +{ + char aCompleteFilename[512]; + unsigned char *pBuffer; + png_t Png; // ignore_convention + + // open file for reading + png_init(0,0); // ignore_convention + + IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType, aCompleteFilename, sizeof(aCompleteFilename)); + if(File) + io_close(File); + else + { + dbg_msg("game/png", "failed to open file. filename='%s'", pFilename); + return 0; + } + + int Error = png_open_file(&Png, aCompleteFilename); // ignore_convention + if(Error != PNG_NO_ERROR) + { + dbg_msg("game/png", "failed to open file. filename='%s'", aCompleteFilename); + if(Error != PNG_FILE_ERROR) + png_close_file(&Png); // ignore_convention + return 0; + } + + if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA)) // ignore_convention + { + dbg_msg("game/png", "invalid format. filename='%s'", aCompleteFilename); + png_close_file(&Png); // ignore_convention + return 0; + } + + pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp, 1); // ignore_convention + png_get_data(&Png, pBuffer); // ignore_convention + png_close_file(&Png); // ignore_convention + + pImg->m_Width = Png.width; // ignore_convention + pImg->m_Height = Png.height; // ignore_convention + if(Png.color_type == PNG_TRUECOLOR) // ignore_convention + pImg->m_Format = CImageInfo::FORMAT_RGB; + else if(Png.color_type == PNG_TRUECOLOR_ALPHA) // ignore_convention + pImg->m_Format = CImageInfo::FORMAT_RGBA; + pImg->m_pData = pBuffer; + return 1; +} + +void CGraphics_Threaded::KickCommandBuffer() +{ + m_pBackend->RunBuffer(m_pCommandBuffer); + + // swap buffer + m_CurrentCommandBuffer ^= 1; + m_pCommandBuffer = m_apCommandBuffers[m_CurrentCommandBuffer]; + m_pCommandBuffer->Reset(); +} + +void CGraphics_Threaded::ScreenshotDirect(const char *pFilename) +{ + // add swap command + CImageInfo Image; + mem_zero(&Image, sizeof(Image)); + + CCommandBuffer::SCommand_Screenshot Cmd; + Cmd.m_pImage = &Image; + m_pCommandBuffer->AddCommand(Cmd); + + // kick the buffer and wait for the result + KickCommandBuffer(); + WaitForIdle(); + + if(Image.m_pData) + { + // find filename + char aWholePath[1024]; + png_t Png; // ignore_convention + + IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath)); + if(File) + io_close(File); + + // save png + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "saved screenshot to '%s'", aWholePath); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); + png_open_file_write(&Png, aWholePath); // ignore_convention + png_set_data(&Png, Image.m_Width, Image.m_Height, 8, PNG_TRUECOLOR, (unsigned char *)Image.m_pData); // ignore_convention + png_close_file(&Png); // ignore_convention + + mem_free(Image.m_pData); + } +} + +void CGraphics_Threaded::TextureSet(int TextureID) +{ + dbg_assert(m_Drawing == 0, "called Graphics()->TextureSet within begin"); + m_State.m_Texture = TextureID; +} + +void CGraphics_Threaded::Clear(float r, float g, float b) +{ + CCommandBuffer::SCommand_Clear Cmd; + Cmd.m_Color.r = r; + Cmd.m_Color.g = g; + Cmd.m_Color.b = b; + Cmd.m_Color.a = 0; + m_pCommandBuffer->AddCommand(Cmd); +} + +void CGraphics_Threaded::QuadsBegin() +{ + dbg_assert(m_Drawing == 0, "called Graphics()->QuadsBegin twice"); + m_Drawing = DRAWING_QUADS; + + QuadsSetSubset(0,0,1,1); + QuadsSetRotation(0); + SetColor(1,1,1,1); +} + +void CGraphics_Threaded::QuadsEnd() +{ + dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsEnd without begin"); + FlushVertices(); + m_Drawing = 0; +} + +void CGraphics_Threaded::QuadsSetRotation(float Angle) +{ + dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsSetRotation without begin"); + m_Rotation = Angle; +} + +void CGraphics_Threaded::SetColorVertex(const CColorVertex *pArray, int Num) +{ + dbg_assert(m_Drawing != 0, "called Graphics()->SetColorVertex without begin"); + + for(int i = 0; i < Num; ++i) + { + m_aColor[pArray[i].m_Index].r = pArray[i].m_R; + m_aColor[pArray[i].m_Index].g = pArray[i].m_G; + m_aColor[pArray[i].m_Index].b = pArray[i].m_B; + m_aColor[pArray[i].m_Index].a = pArray[i].m_A; + } +} + +void CGraphics_Threaded::SetColor(float r, float g, float b, float a) +{ + dbg_assert(m_Drawing != 0, "called Graphics()->SetColor without begin"); + CColorVertex Array[4] = { + CColorVertex(0, r, g, b, a), + CColorVertex(1, r, g, b, a), + CColorVertex(2, r, g, b, a), + CColorVertex(3, r, g, b, a)}; + SetColorVertex(Array, 4); +} + +void CGraphics_Threaded::QuadsSetSubset(float TlU, float TlV, float BrU, float BrV) +{ + dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsSetSubset without begin"); + + m_aTexture[0].u = TlU; m_aTexture[1].u = BrU; + m_aTexture[0].v = TlV; m_aTexture[1].v = TlV; + + m_aTexture[3].u = TlU; m_aTexture[2].u = BrU; + m_aTexture[3].v = BrV; m_aTexture[2].v = BrV; +} + +void CGraphics_Threaded::QuadsSetSubsetFree( + float x0, float y0, float x1, float y1, + float x2, float y2, float x3, float y3) +{ + m_aTexture[0].u = x0; m_aTexture[0].v = y0; + m_aTexture[1].u = x1; m_aTexture[1].v = y1; + m_aTexture[2].u = x2; m_aTexture[2].v = y2; + m_aTexture[3].u = x3; m_aTexture[3].v = y3; +} + +void CGraphics_Threaded::QuadsDraw(CQuadItem *pArray, int Num) +{ + for(int i = 0; i < Num; ++i) + { + pArray[i].m_X -= pArray[i].m_Width/2; + pArray[i].m_Y -= pArray[i].m_Height/2; + } + + QuadsDrawTL(pArray, Num); +} + +void CGraphics_Threaded::QuadsDrawTL(const CQuadItem *pArray, int Num) +{ + CCommandBuffer::SPoint Center; + Center.z = 0; + + dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsDrawTL without begin"); + + for(int i = 0; i < Num; ++i) + { + m_aVertices[m_NumVertices + 4*i].m_Pos.x = pArray[i].m_X; + m_aVertices[m_NumVertices + 4*i].m_Pos.y = pArray[i].m_Y; + m_aVertices[m_NumVertices + 4*i].m_Tex = m_aTexture[0]; + m_aVertices[m_NumVertices + 4*i].m_Color = m_aColor[0]; + + m_aVertices[m_NumVertices + 4*i + 1].m_Pos.x = pArray[i].m_X + pArray[i].m_Width; + m_aVertices[m_NumVertices + 4*i + 1].m_Pos.y = pArray[i].m_Y; + m_aVertices[m_NumVertices + 4*i + 1].m_Tex = m_aTexture[1]; + m_aVertices[m_NumVertices + 4*i + 1].m_Color = m_aColor[1]; + + m_aVertices[m_NumVertices + 4*i + 2].m_Pos.x = pArray[i].m_X + pArray[i].m_Width; + m_aVertices[m_NumVertices + 4*i + 2].m_Pos.y = pArray[i].m_Y + pArray[i].m_Height; + m_aVertices[m_NumVertices + 4*i + 2].m_Tex = m_aTexture[2]; + m_aVertices[m_NumVertices + 4*i + 2].m_Color = m_aColor[2]; + + m_aVertices[m_NumVertices + 4*i + 3].m_Pos.x = pArray[i].m_X; + m_aVertices[m_NumVertices + 4*i + 3].m_Pos.y = pArray[i].m_Y + pArray[i].m_Height; + m_aVertices[m_NumVertices + 4*i + 3].m_Tex = m_aTexture[3]; + m_aVertices[m_NumVertices + 4*i + 3].m_Color = m_aColor[3]; + + if(m_Rotation != 0) + { + Center.x = pArray[i].m_X + pArray[i].m_Width/2; + Center.y = pArray[i].m_Y + pArray[i].m_Height/2; + + Rotate4(Center, &m_aVertices[m_NumVertices + 4*i]); + } + } + + AddVertices(4*Num); +} + +void CGraphics_Threaded::QuadsDrawFreeform(const CFreeformItem *pArray, int Num) +{ + dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsDrawFreeform without begin"); + + for(int i = 0; i < Num; ++i) + { + m_aVertices[m_NumVertices + 4*i].m_Pos.x = pArray[i].m_X0; + m_aVertices[m_NumVertices + 4*i].m_Pos.y = pArray[i].m_Y0; + m_aVertices[m_NumVertices + 4*i].m_Tex = m_aTexture[0]; + m_aVertices[m_NumVertices + 4*i].m_Color = m_aColor[0]; + + m_aVertices[m_NumVertices + 4*i + 1].m_Pos.x = pArray[i].m_X1; + m_aVertices[m_NumVertices + 4*i + 1].m_Pos.y = pArray[i].m_Y1; + m_aVertices[m_NumVertices + 4*i + 1].m_Tex = m_aTexture[1]; + m_aVertices[m_NumVertices + 4*i + 1].m_Color = m_aColor[1]; + + m_aVertices[m_NumVertices + 4*i + 2].m_Pos.x = pArray[i].m_X3; + m_aVertices[m_NumVertices + 4*i + 2].m_Pos.y = pArray[i].m_Y3; + m_aVertices[m_NumVertices + 4*i + 2].m_Tex = m_aTexture[3]; + m_aVertices[m_NumVertices + 4*i + 2].m_Color = m_aColor[3]; + + m_aVertices[m_NumVertices + 4*i + 3].m_Pos.x = pArray[i].m_X2; + m_aVertices[m_NumVertices + 4*i + 3].m_Pos.y = pArray[i].m_Y2; + m_aVertices[m_NumVertices + 4*i + 3].m_Tex = m_aTexture[2]; + m_aVertices[m_NumVertices + 4*i + 3].m_Color = m_aColor[2]; + } + + AddVertices(4*Num); +} + +void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pText) +{ + float StartX = x; + + while(*pText) + { + char c = *pText; + pText++; + + if(c == '\n') + { + x = StartX; + y += Size; + } + else + { + QuadsSetSubset( + (c%16)/16.0f, + (c/16)/16.0f, + (c%16)/16.0f+1.0f/16.0f, + (c/16)/16.0f+1.0f/16.0f); + + CQuadItem QuadItem(x, y, Size, Size); + QuadsDrawTL(&QuadItem, 1); + x += Size/2; + } + } +} + +int CGraphics_Threaded::IssueInit() +{ + int Flags = 0; + if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen) + { + dbg_msg("gfx", "both borderless and fullscreen activated, disabling borderless"); + g_Config.m_GfxBorderless = 0; + } + + if(g_Config.m_GfxBorderless) Flags |= IGraphicsBackend::INITFLAG_BORDERLESS; + else if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN; + if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC; + if(g_Config.m_DbgResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE; + + return m_pBackend->Init("Teeworlds", &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags); +} + +int CGraphics_Threaded::InitWindow() +{ + if(IssueInit() == 0) + return 0; + + // try disabling fsaa + while(g_Config.m_GfxFsaaSamples) + { + g_Config.m_GfxFsaaSamples--; + + if(g_Config.m_GfxFsaaSamples) + dbg_msg("gfx", "lowering FSAA to %d and trying again", g_Config.m_GfxFsaaSamples); + else + dbg_msg("gfx", "disabling FSAA and trying again"); + + if(IssueInit() == 0) + return 0; + } + + // try lowering the resolution + if(g_Config.m_GfxScreenWidth != 640 || g_Config.m_GfxScreenHeight != 480) + { + dbg_msg("gfx", "setting resolution to 640x480 and trying again"); + g_Config.m_GfxScreenWidth = 640; + g_Config.m_GfxScreenHeight = 480; + + if(IssueInit() == 0) + return 0; + } + + dbg_msg("gfx", "out of ideas. failed to init graphics"); + + return -1; +} + +int CGraphics_Threaded::Init() +{ + // fetch pointers + m_pStorage = Kernel()->RequestInterface(); + m_pConsole = Kernel()->RequestInterface(); + + // Set all z to -5.0f + for(int i = 0; i < MAX_VERTICES; i++) + m_aVertices[i].m_Pos.z = -5.0f; + + // init textures + m_FirstFreeTexture = 0; + for(int i = 0; i < MAX_TEXTURES-1; i++) + m_aTextureIndices[i] = i+1; + m_aTextureIndices[MAX_TEXTURES-1] = -1; + + m_pBackend = CreateGraphicsBackend(); + if(InitWindow() != 0) + return -1; + + // fetch final resolusion + m_ScreenWidth = g_Config.m_GfxScreenWidth; + m_ScreenHeight = g_Config.m_GfxScreenHeight; + + // create command buffers + for(int i = 0; i < NUM_CMDBUFFERS; i++) + m_apCommandBuffers[i] = new CCommandBuffer(128*1024, 2*1024*1024); + m_pCommandBuffer = m_apCommandBuffers[0]; + + // create null texture, will get id=0 + static const unsigned char aNullTextureData[] = { + 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, + 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, + 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, + 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, + }; + + m_InvalidTexture = LoadTextureRaw(4,4,CImageInfo::FORMAT_RGBA,aNullTextureData,CImageInfo::FORMAT_RGBA,TEXLOAD_NORESAMPLE); + return 0; +} + +void CGraphics_Threaded::Shutdown() +{ + // shutdown the backend + m_pBackend->Shutdown(); + delete m_pBackend; + m_pBackend = 0x0; + + // delete the command buffers + for(int i = 0; i < NUM_CMDBUFFERS; i++) + delete m_apCommandBuffers[i]; +} + +void CGraphics_Threaded::Minimize() +{ + m_pBackend->Minimize(); +} + +void CGraphics_Threaded::Maximize() +{ + // TODO: SDL + m_pBackend->Maximize(); +} + +int CGraphics_Threaded::WindowActive() +{ + return m_pBackend->WindowActive(); +} + +int CGraphics_Threaded::WindowOpen() +{ + return m_pBackend->WindowOpen(); + +} + +void CGraphics_Threaded::TakeScreenshot(const char *pFilename) +{ + // TODO: screenshot support + char aDate[20]; + str_timestamp(aDate, sizeof(aDate)); + str_format(m_aScreenshotName, sizeof(m_aScreenshotName), "screenshots/%s_%s.png", pFilename?pFilename:"screenshot", aDate); + m_DoScreenshot = true; +} + +void CGraphics_Threaded::Swap() +{ + // TODO: screenshot support + if(m_DoScreenshot) + { + if(WindowActive()) + ScreenshotDirect(m_aScreenshotName); + m_DoScreenshot = false; + } + + // add swap command + CCommandBuffer::SCommand_Swap Cmd; + Cmd.m_Finish = g_Config.m_GfxFinish; + m_pCommandBuffer->AddCommand(Cmd); + + // kick the command buffer + KickCommandBuffer(); +} + +// syncronization +void CGraphics_Threaded::InsertSignal(semaphore *pSemaphore) +{ + CCommandBuffer::SCommand_Signal Cmd; + Cmd.m_pSemaphore = pSemaphore; + m_pCommandBuffer->AddCommand(Cmd); +} + +bool CGraphics_Threaded::IsIdle() +{ + return m_pBackend->IsIdle(); +} + +void CGraphics_Threaded::WaitForIdle() +{ + m_pBackend->WaitForIdle(); +} + +int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes) +{ + if(g_Config.m_GfxDisplayAllModes) + { + int Count = sizeof(g_aFakeModes)/sizeof(CVideoMode); + mem_copy(pModes, g_aFakeModes, sizeof(g_aFakeModes)); + if(MaxModes < Count) + Count = MaxModes; + return Count; + } + + // add videomodes command + CImageInfo Image; + mem_zero(&Image, sizeof(Image)); + + int NumModes = 0; + CCommandBuffer::SCommand_VideoModes Cmd; + Cmd.m_pModes = pModes; + Cmd.m_MaxModes = MaxModes; + Cmd.m_pNumModes = &NumModes; + m_pCommandBuffer->AddCommand(Cmd); + + // kick the buffer and wait for the result and return it + KickCommandBuffer(); + WaitForIdle(); + return NumModes; +} + +extern IEngineGraphics *CreateEngineGraphicsThreaded() { return new CGraphics_Threaded(); } diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/graphics_threaded.h teeworlds-0.6.2+dfsg/src/engine/client/graphics_threaded.h --- teeworlds-0.6.1+dfsg/src/engine/client/graphics_threaded.h 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/graphics_threaded.h 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,444 @@ +#pragma once + +#include + +class CCommandBuffer +{ + class CBuffer + { + unsigned char *m_pData; + unsigned m_Size; + unsigned m_Used; + public: + CBuffer(unsigned BufferSize) + { + m_Size = BufferSize; + m_pData = new unsigned char[m_Size]; + m_Used = 0; + } + + ~CBuffer() + { + delete [] m_pData; + m_pData = 0x0; + m_Used = 0; + m_Size = 0; + } + + void Reset() + { + m_Used = 0; + } + + void *Alloc(unsigned Requested) + { + if(Requested + m_Used > m_Size) + return 0; + void *pPtr = &m_pData[m_Used]; + m_Used += Requested; + return pPtr; + } + + unsigned char *DataPtr() { return m_pData; } + unsigned DataSize() { return m_Size; } + unsigned DataUsed() { return m_Used; } + }; + +public: + CBuffer m_CmdBuffer; + CBuffer m_DataBuffer; + + enum + { + MAX_TEXTURES=1024*4, + }; + + enum + { + // commadn groups + CMDGROUP_CORE = 0, // commands that everyone has to implement + CMDGROUP_PLATFORM_OPENGL = 10000, // commands specific to a platform + CMDGROUP_PLATFORM_SDL = 20000, + + // + CMD_NOP = CMDGROUP_CORE, + + // + CMD_RUNBUFFER, + + // syncronization + CMD_SIGNAL, + + // texture commands + CMD_TEXTURE_CREATE, + CMD_TEXTURE_DESTROY, + CMD_TEXTURE_UPDATE, + + // rendering + CMD_CLEAR, + CMD_RENDER, + + // swap + CMD_SWAP, + + // misc + CMD_SCREENSHOT, + CMD_VIDEOMODES, + + }; + + enum + { + TEXFORMAT_INVALID = 0, + TEXFORMAT_RGB, + TEXFORMAT_RGBA, + TEXFORMAT_ALPHA, + + TEXFLAG_NOMIPMAPS = 1, + TEXFLAG_COMPRESSED = 2, + TEXFLAG_QUALITY = 4, + }; + + enum + { + // + PRIMTYPE_INVALID = 0, + PRIMTYPE_LINES, + PRIMTYPE_QUADS, + }; + + enum + { + BLEND_NONE = 0, + BLEND_ALPHA, + BLEND_ADDITIVE, + }; + + enum + { + WRAP_REPEAT = 0, + WRAP_CLAMP, + }; + + struct SPoint { float x, y, z; }; + struct STexCoord { float u, v; }; + struct SColor { float r, g, b, a; }; + + struct SVertex + { + SPoint m_Pos; + STexCoord m_Tex; + SColor m_Color; + }; + + struct SCommand + { + public: + SCommand(unsigned Cmd) : m_Cmd(Cmd), m_Size(0) {} + unsigned m_Cmd; + unsigned m_Size; + }; + + struct SState + { + int m_BlendMode; + int m_WrapMode; + int m_Texture; + SPoint m_ScreenTL; + SPoint m_ScreenBR; + + // clip + bool m_ClipEnable; + int m_ClipX; + int m_ClipY; + int m_ClipW; + int m_ClipH; + }; + + struct SCommand_Clear : public SCommand + { + SCommand_Clear() : SCommand(CMD_CLEAR) {} + SColor m_Color; + }; + + struct SCommand_Signal : public SCommand + { + SCommand_Signal() : SCommand(CMD_SIGNAL) {} + semaphore *m_pSemaphore; + }; + + struct SCommand_RunBuffer : public SCommand + { + SCommand_RunBuffer() : SCommand(CMD_RUNBUFFER) {} + CCommandBuffer *m_pOtherBuffer; + }; + + struct SCommand_Render : public SCommand + { + SCommand_Render() : SCommand(CMD_RENDER) {} + SState m_State; + unsigned m_PrimType; + unsigned m_PrimCount; + SVertex *m_pVertices; // you should use the command buffer data to allocate vertices for this command + }; + + struct SCommand_Screenshot : public SCommand + { + SCommand_Screenshot() : SCommand(CMD_SCREENSHOT) {} + CImageInfo *m_pImage; // processor will fill this out, the one who adds this command must free the data as well + }; + + struct SCommand_VideoModes : public SCommand + { + SCommand_VideoModes() : SCommand(CMD_VIDEOMODES) {} + + CVideoMode *m_pModes; // processor will fill this in + int m_MaxModes; // maximum of modes the processor can write to the m_pModes + int *m_pNumModes; // processor will write to this pointer + }; + + struct SCommand_Swap : public SCommand + { + SCommand_Swap() : SCommand(CMD_SWAP) {} + + int m_Finish; + }; + + struct SCommand_Texture_Create : public SCommand + { + SCommand_Texture_Create() : SCommand(CMD_TEXTURE_CREATE) {} + + // texture information + int m_Slot; + + int m_Width; + int m_Height; + int m_PixelSize; + int m_Format; + int m_StoreFormat; + int m_Flags; + void *m_pData; // will be freed by the command processor + }; + + struct SCommand_Texture_Update : public SCommand + { + SCommand_Texture_Update() : SCommand(CMD_TEXTURE_UPDATE) {} + + // texture information + int m_Slot; + + int m_X; + int m_Y; + int m_Width; + int m_Height; + int m_Format; + void *m_pData; // will be freed by the command processor + }; + + + struct SCommand_Texture_Destroy : public SCommand + { + SCommand_Texture_Destroy() : SCommand(CMD_TEXTURE_DESTROY) {} + + // texture information + int m_Slot; + }; + + // + CCommandBuffer(unsigned CmdBufferSize, unsigned DataBufferSize) + : m_CmdBuffer(CmdBufferSize), m_DataBuffer(DataBufferSize) + { + } + + void *AllocData(unsigned WantedSize) + { + return m_DataBuffer.Alloc(WantedSize); + } + + template + bool AddCommand(const T &Command) + { + // make sure that we don't do something stupid like ->AddCommand(&Cmd); + (void)static_cast(&Command); + + // allocate and copy the command into the buffer + SCommand *pCmd = (SCommand *)m_CmdBuffer.Alloc(sizeof(Command)); + if(!pCmd) + return false; + mem_copy(pCmd, &Command, sizeof(Command)); + pCmd->m_Size = sizeof(Command); + return true; + } + + SCommand *GetCommand(unsigned *pIndex) + { + if(*pIndex >= m_CmdBuffer.DataUsed()) + return NULL; + + SCommand *pCommand = (SCommand *)&m_CmdBuffer.DataPtr()[*pIndex]; + *pIndex += pCommand->m_Size; + return pCommand; + } + + void Reset() + { + m_CmdBuffer.Reset(); + m_DataBuffer.Reset(); + } +}; + +// interface for the graphics backend +// all these functions are called on the main thread +class IGraphicsBackend +{ +public: + enum + { + INITFLAG_FULLSCREEN = 1, + INITFLAG_VSYNC = 2, + INITFLAG_RESIZABLE = 4, + INITFLAG_BORDERLESS = 8, + }; + + virtual ~IGraphicsBackend() {} + + virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0; + virtual int Shutdown() = 0; + + virtual int MemoryUsage() const = 0; + + virtual void Minimize() = 0; + virtual void Maximize() = 0; + virtual int WindowActive() = 0; + virtual int WindowOpen() = 0; + + virtual void RunBuffer(CCommandBuffer *pBuffer) = 0; + virtual bool IsIdle() const = 0; + virtual void WaitForIdle() = 0; +}; + +class CGraphics_Threaded : public IEngineGraphics +{ + enum + { + NUM_CMDBUFFERS = 2, + + MAX_VERTICES = 32*1024, + MAX_TEXTURES = 1024*4, + + DRAWING_QUADS=1, + DRAWING_LINES=2 + }; + + CCommandBuffer::SState m_State; + IGraphicsBackend *m_pBackend; + + CCommandBuffer *m_apCommandBuffers[NUM_CMDBUFFERS]; + CCommandBuffer *m_pCommandBuffer; + unsigned m_CurrentCommandBuffer; + + // + class IStorage *m_pStorage; + class IConsole *m_pConsole; + + CCommandBuffer::SVertex m_aVertices[MAX_VERTICES]; + int m_NumVertices; + + CCommandBuffer::SColor m_aColor[4]; + CCommandBuffer::STexCoord m_aTexture[4]; + + bool m_RenderEnable; + + float m_Rotation; + int m_Drawing; + bool m_DoScreenshot; + char m_aScreenshotName[128]; + + int m_InvalidTexture; + + int m_aTextureIndices[MAX_TEXTURES]; + int m_FirstFreeTexture; + int m_TextureMemoryUsage; + + void FlushVertices(); + void AddVertices(int Count); + void Rotate4(const CCommandBuffer::SPoint &rCenter, CCommandBuffer::SVertex *pPoints); + + void KickCommandBuffer(); + + int IssueInit(); + int InitWindow(); +public: + CGraphics_Threaded(); + + virtual void ClipEnable(int x, int y, int w, int h); + virtual void ClipDisable(); + + virtual void BlendNone(); + virtual void BlendNormal(); + virtual void BlendAdditive(); + + virtual void WrapNormal(); + virtual void WrapClamp(); + + virtual int MemoryUsage() const; + + virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY); + virtual void GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY); + + virtual void LinesBegin(); + virtual void LinesEnd(); + virtual void LinesDraw(const CLineItem *pArray, int Num); + + virtual int UnloadTexture(int Index); + virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags); + virtual int LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData); + + // simple uncompressed RGBA loaders + virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags); + virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType); + + void ScreenshotDirect(const char *pFilename); + + virtual void TextureSet(int TextureID); + + virtual void Clear(float r, float g, float b); + + virtual void QuadsBegin(); + virtual void QuadsEnd(); + virtual void QuadsSetRotation(float Angle); + + virtual void SetColorVertex(const CColorVertex *pArray, int Num); + virtual void SetColor(float r, float g, float b, float a); + + virtual void QuadsSetSubset(float TlU, float TlV, float BrU, float BrV); + virtual void QuadsSetSubsetFree( + float x0, float y0, float x1, float y1, + float x2, float y2, float x3, float y3); + + virtual void QuadsDraw(CQuadItem *pArray, int Num); + virtual void QuadsDrawTL(const CQuadItem *pArray, int Num); + virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num); + virtual void QuadsText(float x, float y, float Size, const char *pText); + + virtual void Minimize(); + virtual void Maximize(); + + virtual int WindowActive(); + virtual int WindowOpen(); + + virtual int Init(); + virtual void Shutdown(); + + virtual void TakeScreenshot(const char *pFilename); + virtual void Swap(); + + virtual int GetVideoModes(CVideoMode *pModes, int MaxModes); + + // syncronization + virtual void InsertSignal(semaphore *pSemaphore); + virtual bool IsIdle(); + virtual void WaitForIdle(); +}; + +extern IGraphicsBackend *CreateGraphicsBackend(); diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/input.cpp teeworlds-0.6.2+dfsg/src/engine/client/input.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/input.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/input.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -35,6 +35,7 @@ m_InputCurrent = 0; m_InputGrabbed = 0; + m_InputDispatched = false; m_LastRelease = 0; m_ReleaseDelta = -1; @@ -116,10 +117,14 @@ /*if(!input_grabbed && Graphics()->WindowActive()) Input()->MouseModeRelative();*/ - // clear and begin count on the other one - m_InputCurrent^=1; - mem_zero(&m_aInputCount[m_InputCurrent], sizeof(m_aInputCount[m_InputCurrent])); - mem_zero(&m_aInputState[m_InputCurrent], sizeof(m_aInputState[m_InputCurrent])); + if(m_InputDispatched) + { + // clear and begin count on the other one + m_InputCurrent^=1; + mem_zero(&m_aInputCount[m_InputCurrent], sizeof(m_aInputCount[m_InputCurrent])); + mem_zero(&m_aInputState[m_InputCurrent], sizeof(m_aInputState[m_InputCurrent])); + m_InputDispatched = false; + } { int i; diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/serverbrowser.cpp teeworlds-0.6.2+dfsg/src/engine/client/serverbrowser.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/serverbrowser.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/serverbrowser.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -1,6 +1,6 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ -#include // sort +#include // sort TODO: remove this #include #include @@ -26,7 +26,7 @@ CServerBrowser *m_pThis; public: SortWrap(CServerBrowser *t, SortFunc f) : m_pfnSort(f), m_pThis(t) {} - bool operator()(int a, int b) { return (m_pThis->*m_pfnSort)(a, b); } + bool operator()(int a, int b) { return (g_Config.m_BrSortOrder ? (m_pThis->*m_pfnSort)(b, a) : (m_pThis->*m_pfnSort)(a, b)); } }; CServerBrowser::CServerBrowser() @@ -283,27 +283,16 @@ // sort if(g_Config.m_BrSort == IServerBrowser::SORT_NAME) - std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareName)); + std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareName)); else if(g_Config.m_BrSort == IServerBrowser::SORT_PING) - std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortComparePing)); + std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortComparePing)); else if(g_Config.m_BrSort == IServerBrowser::SORT_MAP) - std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareMap)); + std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareMap)); else if(g_Config.m_BrSort == IServerBrowser::SORT_NUMPLAYERS) - std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, + std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, g_Config.m_BrFilterSpectators ? &CServerBrowser::SortCompareNumPlayers : &CServerBrowser::SortCompareNumClients)); else if(g_Config.m_BrSort == IServerBrowser::SORT_GAMETYPE) - std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareGametype)); - - // invert the list if requested - if(g_Config.m_BrSortOrder) - { - for(i = 0; i < m_NumSortedServers/2; i++) - { - int Temp = m_pSortedServerlist[i]; - m_pSortedServerlist[i] = m_pSortedServerlist[m_NumSortedServers-i-1]; - m_pSortedServerlist[m_NumSortedServers-i-1] = Temp; - } - } + std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareGametype)); // set indexes for(i = 0; i < m_NumSortedServers; i++) @@ -381,7 +370,6 @@ }*/ pEntry->m_GotInfo = 1; - Sort(); } CServerBrowser::CServerEntry *CServerBrowser::Add(const NETADDR &Addr) @@ -399,7 +387,7 @@ pEntry->m_Info.m_NetAddr = Addr; pEntry->m_Info.m_Latency = 999; - net_addr_str(&Addr, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aAddress)); + net_addr_str(&Addr, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aAddress), true); str_copy(pEntry->m_Info.m_aName, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aName)); // check if it's a favorite @@ -507,7 +495,7 @@ /* do the broadcast version */ Packet.m_ClientID = -1; mem_zero(&Packet, sizeof(Packet)); - Packet.m_Address.type = NETTYPE_ALL|NETTYPE_LINK_BROADCAST; + Packet.m_Address.type = m_pNetClient->NetType()|NETTYPE_LINK_BROADCAST; Packet.m_Flags = NETSENDFLAG_CONNLESS; Packet.m_DataSize = sizeof(Buffer); Packet.m_pData = Buffer; @@ -539,7 +527,7 @@ if(g_Config.m_Debug) { char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true); char aBuf[256]; str_format(aBuf, sizeof(aBuf),"requesting server info from %s", aAddrStr); m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf); @@ -680,7 +668,7 @@ if(g_Config.m_Debug) { char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "added fav, %s", aAddrStr); m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf); @@ -734,12 +722,11 @@ { CServerBrowser *pSelf = (CServerBrowser *)pUserData; - int i; char aAddrStr[128]; char aBuffer[256]; - for(i = 0; i < pSelf->m_NumFavoriteServers; i++) + for(int i = 0; i < pSelf->m_NumFavoriteServers; i++) { - net_addr_str(&pSelf->m_aFavoriteServers[i], aAddrStr, sizeof(aAddrStr)); + net_addr_str(&pSelf->m_aFavoriteServers[i], aAddrStr, sizeof(aAddrStr), true); str_format(aBuffer, sizeof(aBuffer), "add_favorite %s", aAddrStr); pConfig->WriteLine(aBuffer); } diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/sound.cpp teeworlds-0.6.2+dfsg/src/engine/client/sound.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/sound.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/sound.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -1,8 +1,11 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include #include + #include #include + #include #include "SDL.h" @@ -19,8 +22,6 @@ NUM_SAMPLES = 512, NUM_VOICES = 64, NUM_CHANNELS = 16, - - MAX_FRAMES = 1024 }; struct CSample @@ -63,7 +64,8 @@ static volatile int m_SoundVolume = 100; static int m_NextVoice = 0; - +static int *m_pMixBuffer = 0; // buffer only used by the thread callback function +static unsigned m_MaxFrames = 0; // TODO: there should be a faster way todo this static short Int2Short(int i) @@ -84,26 +86,27 @@ static void Mix(short *pFinalOut, unsigned Frames) { - int aMixBuffer[MAX_FRAMES*2] = {0}; int MasterVol; + mem_zero(m_pMixBuffer, m_MaxFrames*2*sizeof(int)); + Frames = min(Frames, m_MaxFrames); // aquire lock while we are mixing lock_wait(m_SoundLock); - + MasterVol = m_SoundVolume; - + for(unsigned i = 0; i < NUM_VOICES; i++) { if(m_aVoices[i].m_pSample) { // mix voice CVoice *v = &m_aVoices[i]; - int *pOut = aMixBuffer; + int *pOut = m_pMixBuffer; int Step = v->m_pSample->m_Channels; // setup input sources short *pInL = &v->m_pSample->m_pData[v->m_Tick*Step]; short *pInR = &v->m_pSample->m_pData[v->m_Tick*Step+1]; - + unsigned End = v->m_pSample->m_NumFrames-v->m_Tick; int Rvol = v->m_pChannel->m_Vol; @@ -112,7 +115,7 @@ // make sure that we don't go outside the sound data if(Frames < End) End = Frames; - + // check if we have a mono sound if(v->m_pSample->m_Channels == 1) pInR = pInL; @@ -126,14 +129,14 @@ int dy = v->m_Y - m_CenterY; int Dist = (int)sqrtf((float)dx*dx+dy*dy); // float here. nasty int p = IntAbs(dx); - if(Dist < Range) + if(Dist >= 0 && Dist < Range) { // panning if(dx > 0) Lvol = ((Range-p)*Lvol)/Range; else Rvol = ((Range-p)*Rvol)/Range; - + // falloff Lvol = (Lvol*(Range-Dist))/Range; Rvol = (Rvol*(Range-Dist))/Range; @@ -154,7 +157,7 @@ pInR += Step; v->m_Tick++; } - + // free voice if not used any more if(v->m_Tick == v->m_pSample->m_NumFrames) { @@ -165,8 +168,8 @@ } } } - - + + // release the lock lock_release(m_SoundLock); @@ -176,8 +179,8 @@ for(unsigned i = 0; i < Frames; i++) { int j = i<<1; - int vl = ((aMixBuffer[j]*MasterVol)/101)>>8; - int vr = ((aMixBuffer[j+1]*MasterVol)/101)>>8; + int vl = ((m_pMixBuffer[j]*MasterVol)/101)>>8; + int vr = ((m_pMixBuffer[j+1]*MasterVol)/101)>>8; pFinalOut[j] = Int2Short(vl); pFinalOut[j+1] = Int2Short(vr); @@ -201,14 +204,20 @@ m_SoundEnabled = 0; m_pGraphics = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); - + SDL_AudioSpec Format; - + m_SoundLock = lock_create(); - + if(!g_Config.m_SndEnable) return 0; - + + if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) + { + dbg_msg("gfx", "unable to init SDL audio: %s", SDL_GetError()); + return -1; + } + m_MixingRate = g_Config.m_SndRate; // Set 16-bit stereo audio at 22Khz @@ -228,8 +237,11 @@ else dbg_msg("client/sound", "sound init successful"); + m_MaxFrames = g_Config.m_SndBufferSize*2; + m_pMixBuffer = (int *)mem_alloc(m_MaxFrames*2*sizeof(int), 1); + SDL_PauseAudio(0); - + m_SoundEnabled = 1; Update(); // update the volume return 0; @@ -239,24 +251,30 @@ { // update volume int WantedVolume = g_Config.m_SndVolume; - + if(!m_pGraphics->WindowActive() && g_Config.m_SndNonactiveMute) WantedVolume = 0; - + if(WantedVolume != m_SoundVolume) { lock_wait(m_SoundLock); m_SoundVolume = WantedVolume; lock_release(m_SoundLock); } - + return 0; } int CSound::Shutdown() { SDL_CloseAudio(); + SDL_QuitSubSystem(SDL_INIT_AUDIO); lock_destroy(m_SoundLock); + if(m_pMixBuffer) + { + mem_free(m_pMixBuffer); + m_pMixBuffer = 0; + } return 0; } @@ -277,7 +295,7 @@ CSample *pSample = &m_aSamples[SampleID]; int NumFrames = 0; short *pNewData = 0; - + // make sure that we need to convert this sound if(!pSample->m_pData || pSample->m_Rate == m_MixingRate) return; @@ -285,7 +303,7 @@ // allocate new data NumFrames = (int)((pSample->m_NumFrames/(float)pSample->m_Rate)*m_MixingRate); pNewData = (short *)mem_alloc(NumFrames*pSample->m_Channels*sizeof(short), 1); - + for(int i = 0; i < NumFrames; i++) { // resample TODO: this should be done better, like linear atleast @@ -293,7 +311,7 @@ int f = (int)(a*pSample->m_NumFrames); if(f >= pSample->m_NumFrames) f = pSample->m_NumFrames-1; - + // set new data if(pSample->m_Channels == 1) pNewData[i] = pSample->m_pData[f]; @@ -303,7 +321,7 @@ pNewData[i*2+1] = pSample->m_pData[f*2+1]; } } - + // free old data and apply new mem_free(pSample->m_pData); pSample->m_pData = pNewData; @@ -321,15 +339,15 @@ int SampleID = -1; char aError[100]; WavpackContext *pContext; - + // don't waste memory on sound when we are stress testing if(g_Config.m_DbgStress) return -1; - + // no need to load sound when we are running with no sound if(!m_SoundEnabled) return 1; - + if(!m_pStorage) return -1; @@ -372,7 +390,7 @@ dbg_msg("sound/wv", "file is %d Hz, not 44100 Hz. filename='%s'", snd->rate, filename); return -1; }*/ - + if(BitsPerSample != 16) { dbg_msg("sound/wv", "bps is %d, not 16, filname='%s'", BitsPerSample, pFilename); @@ -382,7 +400,7 @@ pData = (int *)mem_alloc(4*m_aSamples*m_aChannels, 1); WavpackUnpackSamples(pContext, pData, m_aSamples); // TODO: check return value pSrc = pData; - + pSample->m_pData = (short *)mem_alloc(2*m_aSamples*m_aChannels, 1); pDst = pSample->m_pData; @@ -428,9 +446,9 @@ { int VoiceID = -1; int i; - + lock_wait(m_SoundLock); - + // search for voice for(i = 0; i < NUM_VOICES; i++) { @@ -442,7 +460,7 @@ break; } } - + // voice found, use it if(VoiceID != -1) { @@ -457,7 +475,7 @@ m_aVoices[VoiceID].m_X = (int)x; m_aVoices[VoiceID].m_Y = (int)y; } - + lock_release(m_SoundLock); return VoiceID; } diff -Nru teeworlds-0.6.1+dfsg/src/engine/client/text.cpp teeworlds-0.6.2+dfsg/src/engine/client/text.cpp --- teeworlds-0.6.1+dfsg/src/engine/client/text.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client/text.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -9,21 +9,11 @@ #include #endif -#ifdef CONF_PLATFORM_MACOSX - #include - #include -#else - #include - #include -#endif - // ft2 texture #include #include FT_FREETYPE_H // TODO: Refactor: clean this up - - enum { MAX_CHARACTERS = 64, @@ -54,7 +44,7 @@ int m_FontSize; FT_Face *m_pFace; - GLuint m_aTextures[2]; + int m_aTextures[2]; int m_TextureWidth; int m_TextureHeight; @@ -107,7 +97,7 @@ float m_TextOutlineB; float m_TextOutlineA; - int m_FontTextureFormat; + //int m_FontTextureFormat; CFont *m_pDefaultFont; @@ -158,26 +148,25 @@ void *pMem = mem_alloc(Width*Height, 1); mem_zero(pMem, Width*Height); - if(pSizeData->m_aTextures[0] == 0) - glGenTextures(2, pSizeData->m_aTextures); - else - FontMemoryUsage -= pSizeData->m_TextureWidth*pSizeData->m_TextureHeight*2; + for(int i = 0; i < 2; i++) + { + if(pSizeData->m_aTextures[i] != 0) + { + Graphics()->UnloadTexture(pSizeData->m_aTextures[i]); + FontMemoryUsage -= pSizeData->m_TextureWidth*pSizeData->m_TextureHeight; + pSizeData->m_aTextures[i] = 0; + } + + pSizeData->m_aTextures[i] = Graphics()->LoadTextureRaw(Width, Height, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS); + FontMemoryUsage += Width*Height; + } pSizeData->m_NumXChars = Xchars; pSizeData->m_NumYChars = Ychars; pSizeData->m_TextureWidth = Width; pSizeData->m_TextureHeight = Height; pSizeData->m_CurrentCharacter = 0; - - for(int i = 0; i < 2; i++) - { - glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, m_FontTextureFormat, Width, Height, 0, m_FontTextureFormat, GL_UNSIGNED_BYTE, pMem); - FontMemoryUsage += Width*Height; - } - + dbg_msg("", "pFont memory usage: %d", FontMemoryUsage); mem_free(pMem); @@ -254,11 +243,16 @@ int x = (SlotID%pSizeData->m_NumXChars) * (pSizeData->m_TextureWidth/pSizeData->m_NumXChars); int y = (SlotID/pSizeData->m_NumXChars) * (pSizeData->m_TextureHeight/pSizeData->m_NumYChars); + Graphics()->LoadTextureRawSub(pSizeData->m_aTextures[Texnum], x, y, + pSizeData->m_TextureWidth/pSizeData->m_NumXChars, + pSizeData->m_TextureHeight/pSizeData->m_NumYChars, + CImageInfo::FORMAT_ALPHA, pData); + /* glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[Texnum]); glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, pSizeData->m_TextureWidth/pSizeData->m_NumXChars, pSizeData->m_TextureHeight/pSizeData->m_NumYChars, - m_FontTextureFormat, GL_UNSIGNED_BYTE, pData); + m_FontTextureFormat, GL_UNSIGNED_BYTE, pData);*/ } // 32k of data used for rendering glyphs @@ -285,7 +279,8 @@ Oldest = i; } - if(time_get()-pSizeData->m_aCharacters[Oldest].m_TouchTime < time_freq()) + if(time_get()-pSizeData->m_aCharacters[Oldest].m_TouchTime < time_freq() && + (pSizeData->m_NumXChars < MAX_CHARACTERS || pSizeData->m_NumYChars < MAX_CHARACTERS)) { IncreaseTextureSize(pSizeData); return GetSlot(pSizeData); @@ -455,7 +450,7 @@ m_pDefaultFont = 0; // GL_LUMINANCE can be good for debugging - m_FontTextureFormat = GL_ALPHA; + //m_FontTextureFormat = GL_ALPHA; } virtual void Init() @@ -620,11 +615,10 @@ if(pCursor->m_Flags&TEXTFLAG_RENDER) { // TODO: Make this better - glEnable(GL_TEXTURE_2D); if (i == 0) - glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[1]); + Graphics()->TextureSet(pSizeData->m_aTextures[1]); else - glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[0]); + Graphics()->TextureSet(pSizeData->m_aTextures[0]); Graphics()->QuadsBegin(); if (i == 0) @@ -645,7 +639,7 @@ Compare.m_Y = DrawY; Compare.m_Flags &= ~TEXTFLAG_RENDER; Compare.m_LineWidth = -1; - TextEx(&Compare, pText, Wlen); + TextEx(&Compare, pCurrent, Wlen); if(Compare.m_X-DrawX > pCursor->m_LineWidth) { diff -Nru teeworlds-0.6.1+dfsg/src/engine/client.h teeworlds-0.6.2+dfsg/src/engine/client.h --- teeworlds-0.6.1+dfsg/src/engine/client.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/client.h 2013-05-01 11:47:39.000000000 +0000 @@ -23,7 +23,7 @@ float m_PredIntraTick; float m_LocalTime; - float m_FrameTime; + float m_RenderFrameTime; int m_GameTickSpeed; public: @@ -68,7 +68,7 @@ inline int GameTickSpeed() const { return m_GameTickSpeed; } // other time access - inline float FrameTime() const { return m_FrameTime; } + inline float RenderFrameTime() const { return m_RenderFrameTime; } inline float LocalTime() const { return m_LocalTime; } // actions diff -Nru teeworlds-0.6.1+dfsg/src/engine/console.h teeworlds-0.6.2+dfsg/src/engine/console.h --- teeworlds-0.6.1+dfsg/src/engine/console.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/console.h 2013-05-01 11:47:39.000000000 +0000 @@ -78,6 +78,7 @@ virtual bool LineIsValid(const char *pStr) = 0; virtual void ExecuteLine(const char *Sptr) = 0; + virtual void ExecuteLineFlag(const char *Sptr, int FlasgMask) = 0; virtual void ExecuteLineStroked(int Stroke, const char *pStr) = 0; virtual void ExecuteFile(const char *pFilename) = 0; diff -Nru teeworlds-0.6.1+dfsg/src/engine/demo.h teeworlds-0.6.2+dfsg/src/engine/demo.h --- teeworlds-0.6.1+dfsg/src/engine/demo.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/demo.h 2013-05-01 11:47:39.000000000 +0000 @@ -5,6 +5,11 @@ #include "kernel.h" +enum +{ + MAX_TIMELINE_MARKERS=64 +}; + struct CDemoHeader { unsigned char m_aMarker[7]; @@ -18,6 +23,12 @@ char m_aTimestamp[20]; }; +struct CTimelineMarkers +{ + char m_aNumTimelineMarkers[4]; + char m_aTimelineMarkers[MAX_TIMELINE_MARKERS][4]; +}; + class IDemoPlayer : public IInterface { MACRO_INTERFACE("demoplayer", 0) @@ -31,6 +42,9 @@ int m_FirstTick; int m_CurrentTick; int m_LastTick; + + int m_NumTimelineMarkers; + int m_aTimelineMarkers[MAX_TIMELINE_MARKERS]; }; enum @@ -42,7 +56,7 @@ ~IDemoPlayer() {} virtual void SetSpeed(float Speed) = 0; - virtual int SetPos(float Precent) = 0; + virtual int SetPos(float Percent) = 0; virtual void Pause() = 0; virtual void Unpause() = 0; virtual const CInfo *BaseInfo() const = 0; diff -Nru teeworlds-0.6.1+dfsg/src/engine/docs/client_time.txt teeworlds-0.6.2+dfsg/src/engine/docs/client_time.txt --- teeworlds-0.6.1+dfsg/src/engine/docs/client_time.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/docs/client_time.txt 2013-05-01 11:47:39.000000000 +0000 @@ -6,6 +6,6 @@ prevtick tick predtick 4 8 14 |---------------------|---------------------| - 0 <- intratick -> 1 + 0 <- intratick -> 1 0 <- ticktime(in s)-> X 0 <- predintratick?-> 1 diff -Nru teeworlds-0.6.1+dfsg/src/engine/docs/prediction.txt teeworlds-0.6.2+dfsg/src/engine/docs/prediction.txt --- teeworlds-0.6.1+dfsg/src/engine/docs/prediction.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/docs/prediction.txt 2013-05-01 11:47:39.000000000 +0000 @@ -8,7 +8,7 @@ > { > int tick; > prediction_reset(); -> +> > for(tick = client_tick()+1; tick <= client_predtick(); tick++) > { > MY_INPUT *input = (MY_INPUT *)client_get_input(); diff -Nru teeworlds-0.6.1+dfsg/src/engine/docs/server_op.txt teeworlds-0.6.2+dfsg/src/engine/docs/server_op.txt --- teeworlds-0.6.1+dfsg/src/engine/docs/server_op.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/docs/server_op.txt 2013-05-01 11:47:39.000000000 +0000 @@ -25,13 +25,13 @@ send snapshot end for end - + process new network messages end while unload map (end) - + Section: Reinit diff -Nru teeworlds-0.6.1+dfsg/src/engine/docs/snapshots.txt teeworlds-0.6.2+dfsg/src/engine/docs/snapshots.txt --- teeworlds-0.6.1+dfsg/src/engine/docs/snapshots.txt 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/docs/snapshots.txt 2013-05-01 11:47:39.000000000 +0000 @@ -48,7 +48,7 @@ Topic: Interval -The interval for how often a client recives a snapshot changes during the course of the connection. There are three different snapshot rates. +The interval for how often a client recives a snapshot changes during the course of the connection. There are three different snapshot rates. - *Init*. 5 snapshots per second. Used when a client is connecting and used until the client has acknowlaged a snapshot. This mechanism is used because the first snapshot because no delta compression can be done. diff -Nru teeworlds-0.6.1+dfsg/src/engine/graphics.h teeworlds-0.6.2+dfsg/src/engine/graphics.h --- teeworlds-0.6.1+dfsg/src/engine/graphics.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/graphics.h 2013-05-01 11:47:39.000000000 +0000 @@ -5,6 +5,7 @@ #include "kernel.h" + class CImageInfo { public: @@ -55,7 +56,8 @@ */ enum { - TEXLOAD_NORESAMPLE=1, + TEXLOAD_NORESAMPLE = 1, + TEXLOAD_NOMIPMAPS = 2, }; int ScreenWidth() const { return m_ScreenWidth; } @@ -74,12 +76,15 @@ virtual void BlendNone() = 0; virtual void BlendNormal() = 0; virtual void BlendAdditive() = 0; + virtual void WrapNormal() = 0; + virtual void WrapClamp() = 0; virtual int MemoryUsage() const = 0; - virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) =0; + virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) = 0; virtual int UnloadTexture(int Index) = 0; virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0; virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0; + virtual int LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData) = 0; virtual void TextureSet(int TextureID) = 0; struct CLineItem @@ -115,7 +120,7 @@ : m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1), m_X2(x2), m_Y2(y2), m_X3(x3), m_Y3(y3) {} }; virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0; - virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) = 0; + virtual void QuadsText(float x, float y, float Size, const char *pText) = 0; struct CColorVertex { @@ -131,13 +136,18 @@ virtual int GetVideoModes(CVideoMode *pModes, int MaxModes) = 0; virtual void Swap() = 0; + + // syncronization + virtual void InsertSignal(class semaphore *pSemaphore) = 0; + virtual bool IsIdle() = 0; + virtual void WaitForIdle() = 0; }; class IEngineGraphics : public IGraphics { MACRO_INTERFACE("enginegraphics", 0) public: - virtual bool Init() = 0; + virtual int Init() = 0; virtual void Shutdown() = 0; virtual void Minimize() = 0; @@ -149,5 +159,6 @@ }; extern IEngineGraphics *CreateEngineGraphics(); +extern IEngineGraphics *CreateEngineGraphicsThreaded(); #endif diff -Nru teeworlds-0.6.1+dfsg/src/engine/input.h teeworlds-0.6.2+dfsg/src/engine/input.h --- teeworlds-0.6.1+dfsg/src/engine/input.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/input.h 2013-05-01 11:47:39.000000000 +0000 @@ -38,6 +38,7 @@ unsigned char m_aInputState[2][1024]; int m_InputCurrent; + bool m_InputDispatched; int KeyWasPressed(int Key) { return m_aInputState[m_InputCurrent^1][Key]; } @@ -51,7 +52,11 @@ // events int NumEvents() const { return m_NumEvents; } - void ClearEvents() { m_NumEvents = 0; } + void ClearEvents() + { + m_NumEvents = 0; + m_InputDispatched = true; + } CEvent GetEvent(int Index) const { if(Index < 0 || Index >= m_NumEvents) diff -Nru teeworlds-0.6.1+dfsg/src/engine/server/server.cpp teeworlds-0.6.2+dfsg/src/engine/server/server.cpp --- teeworlds-0.6.1+dfsg/src/engine/server/server.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/server/server.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -55,17 +56,6 @@ } -static int StrAllnum(const char *pStr) -{ - while(*pStr) - { - if(!(*pStr >= '0' && *pStr <= '9')) - return 0; - pStr++; - } - return 1; -} - CSnapIDPool::CSnapIDPool() { Reset(); @@ -154,6 +144,115 @@ } } + +void CServerBan::InitServerBan(IConsole *pConsole, IStorage *pStorage, CServer* pServer) +{ + CNetBan::Init(pConsole, pStorage); + + m_pServer = pServer; + + // overwrites base command, todo: improve this + Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_STORE, ConBanExt, this, "Ban player with ip/client id for x minutes for any reason"); +} + +template +int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason) +{ + // validate address + if(Server()->m_RconClientID >= 0 && Server()->m_RconClientID < MAX_CLIENTS && + Server()->m_aClients[Server()->m_RconClientID].m_State != CServer::CClient::STATE_EMPTY) + { + if(NetMatch(pData, Server()->m_NetServer.ClientAddr(Server()->m_RconClientID))) + { + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (you can't ban yourself)"); + return -1; + } + + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(i == Server()->m_RconClientID || Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY) + continue; + + if(Server()->m_aClients[i].m_Authed >= Server()->m_RconAuthLevel && NetMatch(pData, Server()->m_NetServer.ClientAddr(i))) + { + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (command denied)"); + return -1; + } + } + } + else if(Server()->m_RconClientID == IServer::RCON_CID_VOTE) + { + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY) + continue; + + if(Server()->m_aClients[i].m_Authed != CServer::AUTHED_NO && NetMatch(pData, Server()->m_NetServer.ClientAddr(i))) + { + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (command denied)"); + return -1; + } + } + } + + int Result = Ban(pBanPool, pData, Seconds, pReason); + if(Result != 0) + return Result; + + // drop banned clients + typename T::CDataType Data = *pData; + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY) + continue; + + if(NetMatch(&Data, Server()->m_NetServer.ClientAddr(i))) + { + CNetHash NetHash(&Data); + char aBuf[256]; + MakeBanInfo(pBanPool->Find(&Data, &NetHash), aBuf, sizeof(aBuf), MSGTYPE_PLAYER); + Server()->m_NetServer.Drop(i, aBuf); + } + } + + return Result; +} + +int CServerBan::BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason) +{ + return BanExt(&m_BanAddrPool, pAddr, Seconds, pReason); +} + +int CServerBan::BanRange(const CNetRange *pRange, int Seconds, const char *pReason) +{ + if(pRange->IsValid()) + return BanExt(&m_BanRangePool, pRange, Seconds, pReason); + + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (invalid range)"); + return -1; +} + +void CServerBan::ConBanExt(IConsole::IResult *pResult, void *pUser) +{ + CServerBan *pThis = static_cast(pUser); + + const char *pStr = pResult->GetString(0); + int Minutes = pResult->NumArguments()>1 ? clamp(pResult->GetInteger(1), 0, 44640) : 30; + const char *pReason = pResult->NumArguments()>2 ? pResult->GetString(2) : "No reason given"; + + if(StrAllnum(pStr)) + { + int ClientID = str_toint(pStr); + if(ClientID < 0 || ClientID >= MAX_CLIENTS || pThis->Server()->m_aClients[ClientID].m_State == CServer::CClient::STATE_EMPTY) + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid client id)"); + else + pThis->BanAddr(pThis->Server()->m_NetServer.ClientAddr(ClientID), Minutes*60, pReason); + } + else + ConBan(pResult, pUser); +} + + void CServer::CClient::Reset() { // reset input @@ -183,7 +282,7 @@ m_MapReload = 0; - m_RconClientID = -1; + m_RconClientID = IServer::RCON_CID_SERV; m_RconAuthLevel = AUTHED_ADMIN; Init(); @@ -198,6 +297,10 @@ str_copy(aTrimmedName, StrLtrim(pName), sizeof(aTrimmedName)); StrRtrim(aTrimmedName); + // check for empty names + if(!aTrimmedName[0]) + return -1; + // check if new and old name are the same if(m_aClients[ClientID].m_aName[0] && str_comp(m_aClients[ClientID].m_aName, aTrimmedName) == 0) return 0; @@ -207,11 +310,6 @@ Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); pName = aTrimmedName; - - // check for empty names - if(!pName[0]) - return -1; - // make sure that two clients doesn't have the same name for(int i = 0; i < MAX_CLIENTS; i++) if(i != ClientID && m_aClients[i].m_State >= CClient::STATE_READY) @@ -235,14 +333,23 @@ if(!pName) return; - char aNameTry[MAX_NAME_LENGTH]; - str_copy(aNameTry, pName, MAX_NAME_LENGTH); - if(TrySetClientName(ClientID, aNameTry)) + char aCleanName[MAX_NAME_LENGTH]; + str_copy(aCleanName, pName, sizeof(aCleanName)); + + // clear name + for(char *p = aCleanName; *p; ++p) + { + if(*p < 32) + *p = ' '; + } + + if(TrySetClientName(ClientID, aCleanName)) { // auto rename for(int i = 1;; i++) { - str_format(aNameTry, MAX_NAME_LENGTH, "(%d)%s", i, pName); + char aNameTry[MAX_NAME_LENGTH]; + str_format(aNameTry, sizeof(aCleanName), "(%d)%s", i, aCleanName); if(TrySetClientName(ClientID, aNameTry) == 0) break; } @@ -324,6 +431,11 @@ return 0; } +void CServer::SetRconCID(int ClientID) +{ + m_RconClientID = ClientID; +} + bool CServer::IsAuthed(int ClientID) { return m_aClients[ClientID].m_Authed; @@ -346,11 +458,7 @@ void CServer::GetClientAddr(int ClientID, char *pAddrStr, int Size) { if(ClientID >= 0 && ClientID < MAX_CLIENTS && m_aClients[ClientID].m_State == CClient::STATE_INGAME) - { - NETADDR Addr = m_NetServer.ClientAddr(ClientID); - Addr.port = 0; - net_addr_str(&Addr, pAddrStr, Size); - } + net_addr_str(m_NetServer.ClientAddr(ClientID), pAddrStr, Size, false); } @@ -390,6 +498,11 @@ return ClientID >= 0 && ClientID < MAX_CLIENTS && m_aClients[ClientID].m_State == CServer::CClient::STATE_INGAME; } +int CServer::MaxClients() const +{ + return m_NetServer.MaxClients(); +} + int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) { return SendMsgEx(pMsg, Flags, ClientID, false); @@ -591,9 +704,8 @@ { CServer *pThis = (CServer *)pUser; - NETADDR Addr = pThis->m_NetServer.ClientAddr(ClientID); char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(pThis->m_NetServer.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "client dropped. cid=%d addr=%s reason='%s'", ClientID, aAddrStr, pReason); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); @@ -672,7 +784,7 @@ void CServer::UpdateClientRconCommands() { int ClientID = Tick() % MAX_CLIENTS; - + if(m_aClients[ClientID].m_State != CClient::STATE_EMPTY && m_aClients[ClientID].m_Authed) { int ConsoleAccessLevel = m_aClients[ClientID].m_Authed == AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : IConsole::ACCESS_LEVEL_MOD; @@ -687,7 +799,6 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) { int ClientID = pPacket->m_ClientID; - NETADDR Addr; CUnpacker Unpacker; Unpacker.Reset(pPacket->m_pData, pPacket->m_DataSize); @@ -730,6 +841,9 @@ } else if(Msg == NETMSG_REQUEST_MAP_DATA) { + if(m_aClients[ClientID].m_State < CClient::STATE_CONNECTING) + return; + int Chunk = Unpacker.GetInt(); int ChunkSize = 1024-128; int Offset = Chunk * ChunkSize; @@ -766,9 +880,8 @@ { if(m_aClients[ClientID].m_State == CClient::STATE_CONNECTING) { - Addr = m_NetServer.ClientAddr(ClientID); char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(m_NetServer.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "player is ready. ClientID=%x addr=%s", ClientID, aAddrStr); @@ -782,9 +895,8 @@ { if(m_aClients[ClientID].m_State == CClient::STATE_READY && GameServer()->IsClientReady(ClientID)) { - Addr = m_NetServer.ClientAddr(ClientID); char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(m_NetServer.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "player has entered the game. ClientID=%x addr=%s", ClientID, aAddrStr); @@ -857,9 +969,9 @@ m_RconClientID = ClientID; m_RconAuthLevel = m_aClients[ClientID].m_Authed; Console()->SetAccessLevel(m_aClients[ClientID].m_Authed == AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : IConsole::ACCESS_LEVEL_MOD); - Console()->ExecuteLine(pCmd); + Console()->ExecuteLineFlag(pCmd, CFGFLAG_SERVER); Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_ADMIN); - m_RconClientID = -1; + m_RconClientID = IServer::RCON_CID_SERV; m_RconAuthLevel = AUTHED_ADMIN; } } @@ -918,10 +1030,7 @@ if(!g_Config.m_SvRconBantime) m_NetServer.Drop(ClientID, "Too many remote console authentication tries"); else - { - NETADDR Addr = m_NetServer.ClientAddr(ClientID); - BanAdd(Addr, g_Config.m_SvRconBantime*60, "Too many remote console authentication tries"); - } + m_ServerBan.BanAddr(m_NetServer.ClientAddr(ClientID), g_Config.m_SvRconBantime*60, "Too many remote console authentication tries"); } } else @@ -965,7 +1074,7 @@ } } -void CServer::SendServerInfo(NETADDR *pAddr, int Token) +void CServer::SendServerInfo(const NETADDR *pAddr, int Token) { CNetChunk Packet; CPacker p; @@ -1034,33 +1143,10 @@ for(int i = 0; i < MAX_CLIENTS; ++i) { if(m_aClients[i].m_State != CClient::STATE_EMPTY) - { - NETADDR Addr = m_NetServer.ClientAddr(i); - SendServerInfo(&Addr, -1); - } + SendServerInfo(m_NetServer.ClientAddr(i), -1); } } -int CServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason) -{ - Addr.port = 0; - char aAddrStr[128]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); - char aBuf[256]; - if(Seconds) - str_format(aBuf, sizeof(aBuf), "banned %s for %d minutes", aAddrStr, Seconds/60); - else - str_format(aBuf, sizeof(aBuf), "banned %s for life", aAddrStr); - Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - - return m_NetServer.BanAdd(Addr, Seconds, pReason); -} - -int CServer::BanRemove(NETADDR Addr) -{ - return m_NetServer.BanRemove(Addr); -} - void CServer::PumpNetwork() { @@ -1087,6 +1173,7 @@ ProcessClientPacket(&Packet); } + m_ServerBan.Update(); m_Econ.Update(); } @@ -1137,7 +1224,7 @@ str_copy(m_aCurrentMap, pMapName, sizeof(m_aCurrentMap)); //map_set(df); - // load compelate map into memory for download + // load complete map into memory for download { IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL); m_CurrentMapSize = (int)io_length(File); @@ -1157,10 +1244,6 @@ int CServer::Run() { - m_pGameServer = Kernel()->RequestInterface(); - m_pMap = Kernel()->RequestInterface(); - m_pStorage = Kernel()->RequestInterface(); - // m_PrintCBIndex = Console()->RegisterPrintCallback(g_Config.m_ConsoleOutputLevel, SendRconLineAuthed, this); @@ -1173,9 +1256,10 @@ // start server NETADDR BindAddr; - if(g_Config.m_SvBindaddr[0] && net_host_lookup(g_Config.m_SvBindaddr, &BindAddr, NETTYPE_ALL) == 0) + if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0) { // sweet! + BindAddr.type = NETTYPE_ALL; BindAddr.port = g_Config.m_SvPort; } else @@ -1185,15 +1269,15 @@ BindAddr.port = g_Config.m_SvPort; } - if(!m_NetServer.Open(BindAddr, g_Config.m_SvMaxClients, g_Config.m_SvMaxClientsPerIP, 0)) + if(!m_NetServer.Open(BindAddr, &m_ServerBan, g_Config.m_SvMaxClients, g_Config.m_SvMaxClientsPerIP, 0)) { - dbg_msg("server", "couldn't open socket. port might already be in use"); + dbg_msg("server", "couldn't open socket. port %d might already be in use", g_Config.m_SvPort); return -1; } m_NetServer.SetCallbacks(NewClientCallback, DelClientCallback, this); - m_Econ.Init(Console()); + m_Econ.Init(Console(), &m_ServerBan); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "server name is '%s'", g_Config.m_SvName); @@ -1356,163 +1440,27 @@ ((CServer *)pUser)->Kick(pResult->GetInteger(0), "Kicked by console"); } -void CServer::ConBan(IConsole::IResult *pResult, void *pUser) -{ - NETADDR Addr; - CServer *pServer = (CServer *)pUser; - const char *pStr = pResult->GetString(0); - int Minutes = 30; - const char *pReason = "No reason given"; - - if(pResult->NumArguments() > 1) - Minutes = max(0, pResult->GetInteger(1)); - - if(pResult->NumArguments() > 2) - pReason = pResult->GetString(2); - - if(net_addr_from_str(&Addr, pStr) == 0) - { - if(pServer->m_RconClientID >= 0 && pServer->m_RconClientID < MAX_CLIENTS && pServer->m_aClients[pServer->m_RconClientID].m_State != CClient::STATE_EMPTY) - { - NETADDR AddrCheck = pServer->m_NetServer.ClientAddr(pServer->m_RconClientID); - Addr.port = AddrCheck.port = 0; - if(net_addr_comp(&Addr, &AddrCheck) == 0) - { - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself"); - return; - } - - for(int i = 0; i < MAX_CLIENTS; ++i) - { - if(i == pServer->m_RconClientID) - continue; - - AddrCheck = pServer->m_NetServer.ClientAddr(i); - AddrCheck.port = 0; - if(net_addr_comp(&Addr, &AddrCheck) == 0 && pServer->m_aClients[i].m_Authed > pServer->m_RconAuthLevel) - { - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "ban command denied"); - return; - } - } - } - pServer->BanAdd(Addr, Minutes*60, pReason); - } - else if(StrAllnum(pStr)) - { - int ClientID = str_toint(pStr); - - if(ClientID < 0 || ClientID >= MAX_CLIENTS || pServer->m_aClients[ClientID].m_State == CClient::STATE_EMPTY) - { - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid client id"); - return; - } - else if(pServer->m_RconClientID == ClientID) - { - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself"); - return; - } - else if(pServer->m_aClients[ClientID].m_Authed > pServer->m_RconAuthLevel) - { - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "ban command denied"); - return; - } - - Addr = pServer->m_NetServer.ClientAddr(ClientID); - pServer->BanAdd(Addr, Minutes*60, pReason); - } - else - { - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address to ban"); - return; - } -} - -void CServer::ConUnban(IConsole::IResult *pResult, void *pUser) -{ - NETADDR Addr; - CServer *pServer = (CServer *)pUser; - const char *pStr = pResult->GetString(0); - - if(net_addr_from_str(&Addr, pStr) == 0 && !pServer->BanRemove(Addr)) - { - char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); - - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "unbanned %s", aAddrStr); - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - } - else if(StrAllnum(pStr)) - { - int BanIndex = str_toint(pStr); - CNetServer::CBanInfo Info; - if(BanIndex < 0 || !pServer->m_NetServer.BanGet(BanIndex, &Info)) - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid ban index"); - else if(!pServer->BanRemove(Info.m_Addr)) - { - char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Info.m_Addr, aAddrStr, sizeof(aAddrStr)); - - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "unbanned %s", aAddrStr); - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - } - } - else - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address"); -} - -void CServer::ConBans(IConsole::IResult *pResult, void *pUser) -{ - unsigned Now = time_timestamp(); - char aBuf[1024]; - char aAddrStr[NETADDR_MAXSTRSIZE]; - CServer* pServer = (CServer *)pUser; - - int Num = pServer->m_NetServer.BanNum(); - for(int i = 0; i < Num; i++) - { - CNetServer::CBanInfo Info; - pServer->m_NetServer.BanGet(i, &Info); - NETADDR Addr = Info.m_Addr; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); - - if(Info.m_Expires == -1) - { - str_format(aBuf, sizeof(aBuf), "#%i %s for life", i, aAddrStr); - } - else - { - unsigned t = Info.m_Expires - Now; - str_format(aBuf, sizeof(aBuf), "#%i %s for %d minutes and %d seconds", i, aAddrStr, t/60, t%60); - } - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); - } - str_format(aBuf, sizeof(aBuf), "%d ban(s)", Num); - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); -} - void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) { - int i; - NETADDR Addr; char aBuf[1024]; char aAddrStr[NETADDR_MAXSTRSIZE]; - CServer* pServer = (CServer *)pUser; + CServer* pThis = static_cast(pUser); - for(i = 0; i < MAX_CLIENTS; i++) + for(int i = 0; i < MAX_CLIENTS; i++) { - if(pServer->m_aClients[i].m_State != CClient::STATE_EMPTY) + if(pThis->m_aClients[i].m_State != CClient::STATE_EMPTY) { - Addr = pServer->m_NetServer.ClientAddr(i); - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); - if(pServer->m_aClients[i].m_State == CClient::STATE_INGAME) - str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d", i, aAddrStr, - pServer->m_aClients[i].m_aName, pServer->m_aClients[i].m_Score); + net_addr_str(pThis->m_NetServer.ClientAddr(i), aAddrStr, sizeof(aAddrStr), true); + if(pThis->m_aClients[i].m_State == CClient::STATE_INGAME) + { + const char *pAuthStr = pThis->m_aClients[i].m_Authed == CServer::AUTHED_ADMIN ? "(Admin)" : + pThis->m_aClients[i].m_Authed == CServer::AUTHED_MOD ? "(Mod)" : ""; + str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d %s", i, aAddrStr, + pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, pAuthStr); + } else str_format(aBuf, sizeof(aBuf), "id=%d addr=%s connecting", i, aAddrStr); - pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); } } } @@ -1541,6 +1489,11 @@ } } +bool CServer::DemoRecorder_IsRecording() +{ + return m_DemoRecorder.IsRecording(); +} + void CServer::ConRecord(IConsole::IResult *pResult, void *pUser) { CServer* pServer = (CServer *)pUser; @@ -1567,6 +1520,28 @@ ((CServer *)pUser)->m_MapReload = 1; } +void CServer::ConLogout(IConsole::IResult *pResult, void *pUser) +{ + CServer *pServer = (CServer *)pUser; + + if(pServer->m_RconClientID >= 0 && pServer->m_RconClientID < MAX_CLIENTS && + pServer->m_aClients[pServer->m_RconClientID].m_State != CServer::CClient::STATE_EMPTY) + { + CMsgPacker Msg(NETMSG_RCON_AUTH_STATUS); + Msg.AddInt(0); //authed + Msg.AddInt(0); //cmdlist + pServer->SendMsgEx(&Msg, MSGFLAG_VITAL, pServer->m_RconClientID, true); + + pServer->m_aClients[pServer->m_RconClientID].m_Authed = AUTHED_NO; + pServer->m_aClients[pServer->m_RconClientID].m_AuthTries = 0; + pServer->m_aClients[pServer->m_RconClientID].m_pRconCmdToSend = 0; + pServer->SendRconLine(pServer->m_RconClientID, "Logout successful."); + char aBuf[32]; + str_format(aBuf, sizeof(aBuf), "ClientID=%d logged out", pServer->m_RconClientID); + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + } +} + void CServer::ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) { pfnCallback(pResult, pCallbackUserData); @@ -1587,7 +1562,7 @@ { CServer *pThis = static_cast(pUserData); const IConsole::CCommandInfo *pInfo = pThis->Console()->GetCommandInfo(pResult->GetString(0), CFGFLAG_SERVER, false); - int OldAccessLevel; + int OldAccessLevel = 0; if(pInfo) OldAccessLevel = pInfo->GetAccessLevel(); pfnCallback(pResult, pCallbackUserData); @@ -1623,13 +1598,15 @@ void CServer::RegisterCommands() { m_pConsole = Kernel()->RequestInterface(); + m_pGameServer = Kernel()->RequestInterface(); + m_pMap = Kernel()->RequestInterface(); + m_pStorage = Kernel()->RequestInterface(); + // register console commands Console()->Register("kick", "i?r", CFGFLAG_SERVER, ConKick, this, "Kick player with specified id for any reason"); - Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_STORE, ConBan, this, "Ban player with ip/id for x minutes for any reason"); - Console()->Register("unban", "s", CFGFLAG_SERVER|CFGFLAG_STORE, ConUnban, this, "Unban ip"); - Console()->Register("bans", "", CFGFLAG_SERVER|CFGFLAG_STORE, ConBans, this, "Show banlist"); Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "List players"); Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, "Shut down"); + Console()->Register("logout", "", CFGFLAG_SERVER, ConLogout, this, "Logout of rcon"); Console()->Register("record", "?s", CFGFLAG_SERVER|CFGFLAG_STORE, ConRecord, this, "Record to a file"); Console()->Register("stoprecord", "", CFGFLAG_SERVER, ConStopRecord, this, "Stop recording"); @@ -1642,6 +1619,10 @@ Console()->Chain("sv_max_clients_per_ip", ConchainMaxclientsperipUpdate, this); Console()->Chain("mod_command", ConchainModCommandUpdate, this); Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this); + + // register console commands in sub parts + m_ServerBan.InitServerBan(Console(), Storage(), this); + m_pGameServer->OnConsoleInit(); } @@ -1690,9 +1671,9 @@ IEngine *pEngine = CreateEngine("Teeworlds"); IEngineMap *pEngineMap = CreateEngineMap(); IGameServer *pGameServer = CreateGameServer(); - IConsole *pConsole = CreateConsole(CFGFLAG_SERVER); + IConsole *pConsole = CreateConsole(CFGFLAG_SERVER|CFGFLAG_ECON); IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer(); - IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention + IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_SERVER, argc, argv); // ignore_convention IConfig *pConfig = CreateConfig(); pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer, pConsole); @@ -1722,7 +1703,6 @@ // register all console commands pServer->RegisterCommands(); - pGameServer->OnConsoleInit(); // execute autoexec file pConsole->ExecuteFile("autoexec.cfg"); diff -Nru teeworlds-0.6.1+dfsg/src/engine/server/server.h teeworlds-0.6.2+dfsg/src/engine/server/server.h --- teeworlds-0.6.1+dfsg/src/engine/server/server.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/server/server.h 2013-05-01 11:47:39.000000000 +0000 @@ -5,6 +5,7 @@ #include + class CSnapIDPool { enum @@ -39,6 +40,25 @@ void FreeID(int ID); }; + +class CServerBan : public CNetBan +{ + class CServer *m_pServer; + + template int BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason); + +public: + class CServer *Server() const { return m_pServer; } + + void InitServerBan(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer); + + virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); + virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); + + static void ConBanExt(class IConsole::IResult *pResult, void *pUser); +}; + + class CServer : public IServer { class IGameServer *m_pGameServer; @@ -114,6 +134,7 @@ CSnapIDPool m_IDPool; CNetServer m_NetServer; CEcon m_Econ; + CServerBan m_ServerBan; IEngineMap *m_pMap; @@ -149,6 +170,7 @@ void Kick(int ClientID, const char *pReason); void DemoRecorder_HandleAutoStart(); + bool DemoRecorder_IsRecording(); //int Tick() int64 TickStartTime(int Tick); @@ -156,6 +178,7 @@ int Init(); + void SetRconCID(int ClientID); bool IsAuthed(int ClientID); int GetClientInfo(int ClientID, CClientInfo *pInfo); void GetClientAddr(int ClientID, char *pAddrStr, int Size); @@ -163,6 +186,7 @@ const char *ClientClan(int ClientID); int ClientCountry(int ClientID); bool ClientIngame(int ClientID); + int MaxClients() const; virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID); int SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System); @@ -183,12 +207,9 @@ void ProcessClientPacket(CNetChunk *pPacket); - void SendServerInfo(NETADDR *pAddr, int Token); + void SendServerInfo(const NETADDR *pAddr, int Token); void UpdateServerInfo(); - int BanAdd(NETADDR Addr, int Seconds, const char *pReason); - int BanRemove(NETADDR Addr); - void PumpNetwork(); char *GetMapName(); @@ -198,14 +219,12 @@ int Run(); static void ConKick(IConsole::IResult *pResult, void *pUser); - static void ConBan(IConsole::IResult *pResult, void *pUser); - static void ConUnban(IConsole::IResult *pResult, void *pUser); - static void ConBans(IConsole::IResult *pResult, void *pUser); - static void ConStatus(IConsole::IResult *pResult, void *pUser); + static void ConStatus(IConsole::IResult *pResult, void *pUser); static void ConShutdown(IConsole::IResult *pResult, void *pUser); static void ConRecord(IConsole::IResult *pResult, void *pUser); static void ConStopRecord(IConsole::IResult *pResult, void *pUser); static void ConMapReload(IConsole::IResult *pResult, void *pUser); + static void ConLogout(IConsole::IResult *pResult, void *pUser); static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); static void ConchainModCommandUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); diff -Nru teeworlds-0.6.1+dfsg/src/engine/server.h teeworlds-0.6.2+dfsg/src/engine/server.h --- teeworlds-0.6.1+dfsg/src/engine/server.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/server.h 2013-05-01 11:47:39.000000000 +0000 @@ -25,6 +25,7 @@ int Tick() const { return m_CurrentGameTick; } int TickSpeed() const { return m_TickSpeed; } + virtual int MaxClients() const = 0; virtual const char *ClientName(int ClientID) = 0; virtual const char *ClientClan(int ClientID) = 0; virtual int ClientCountry(int ClientID) = 0; @@ -54,10 +55,17 @@ virtual void SnapSetStaticsize(int ItemType, int Size) = 0; + enum + { + RCON_CID_SERV=-1, + RCON_CID_VOTE=-2, + }; + virtual void SetRconCID(int ClientID) = 0; virtual bool IsAuthed(int ClientID) = 0; virtual void Kick(int ClientID, const char *pReason) = 0; virtual void DemoRecorder_HandleAutoStart() = 0; + virtual bool DemoRecorder_IsRecording() = 0; }; class IGameServer : public IInterface diff -Nru teeworlds-0.6.1+dfsg/src/engine/serverbrowser.h teeworlds-0.6.2+dfsg/src/engine/serverbrowser.h --- teeworlds-0.6.1+dfsg/src/engine/serverbrowser.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/serverbrowser.h 2013-05-01 11:47:39.000000000 +0000 @@ -24,7 +24,7 @@ int m_Country; int m_Score; bool m_Player; - + int m_FriendState; }; diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/config.cpp teeworlds-0.6.2+dfsg/src/engine/shared/config.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/config.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/config.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -111,13 +111,8 @@ { if(!m_ConfigFile) return; -#if defined(CONF_FAMILY_WINDOWS) - static const char Newline[] = "\r\n"; -#else - static const char Newline[] = "\n"; -#endif io_write(m_ConfigFile, pLine, str_length(pLine)); - io_write(m_ConfigFile, Newline, sizeof(Newline)-1); + io_write_newline(m_ConfigFile); } }; diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/config.h teeworlds-0.6.2+dfsg/src/engine/shared/config.h --- teeworlds-0.6.1+dfsg/src/engine/shared/config.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/config.h 2013-05-01 11:47:39.000000000 +0000 @@ -20,7 +20,8 @@ CFGFLAG_CLIENT=2, CFGFLAG_SERVER=4, CFGFLAG_STORE=8, - CFGFLAG_MASTER=16 + CFGFLAG_MASTER=16, + CFGFLAG_ECON=32, }; #endif diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/config_variables.h teeworlds-0.6.2+dfsg/src/engine/shared/config_variables.h --- teeworlds-0.6.1+dfsg/src/engine/shared/config_variables.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/config_variables.h 2013-05-01 11:47:39.000000000 +0000 @@ -15,8 +15,9 @@ MACRO_CONFIG_STR(Logfile, logfile, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT|CFGFLAG_SERVER, "Filename to log all output to") MACRO_CONFIG_INT(ConsoleOutputLevel, console_output_level, 0, 0, 2, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Adjusts the amount of information in the console") -MACRO_CONFIG_INT(ClCpuThrottle, cl_cpu_throttle, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") +MACRO_CONFIG_INT(ClCpuThrottle, cl_cpu_throttle, 0, 0, 100, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(ClEditor, cl_editor, 0, 0, 1, CFGFLAG_CLIENT, "") +MACRO_CONFIG_INT(ClLoadCountryFlags, cl_load_country_flags, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Load and show country flags") MACRO_CONFIG_INT(ClAutoDemoRecord, cl_auto_demo_record, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Automatically record demos") MACRO_CONFIG_INT(ClAutoDemoMax, cl_auto_demo_max, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Maximum number of automatically recorded demos (0 = no limit)") @@ -47,7 +48,7 @@ MACRO_CONFIG_INT(BrSortOrder, br_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(BrMaxRequests, br_max_requests, 25, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Number of requests to use when refreshing server browser") -MACRO_CONFIG_INT(SndBufferSize, snd_buffer_size, 512, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size") +MACRO_CONFIG_INT(SndBufferSize, snd_buffer_size, 512, 128, 32768, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size") MACRO_CONFIG_INT(SndRate, snd_rate, 48000, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate") MACRO_CONFIG_INT(SndEnable, snd_enable, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound enable") MACRO_CONFIG_INT(SndMusic, snd_enable_music, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Play background music") @@ -56,8 +57,9 @@ MACRO_CONFIG_INT(SndNonactiveMute, snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 800, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width") -MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 600, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height") +MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width") +MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height") +MACRO_CONFIG_INT(GfxBorderless, gfx_borderless, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Borderless window (not to be used with fullscreen)") MACRO_CONFIG_INT(GfxFullscreen, gfx_fullscreen, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Fullscreen") MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)") MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)") @@ -70,11 +72,14 @@ MACRO_CONFIG_INT(GfxFsaaSamples, gfx_fsaa_samples, 0, 0, 16, CFGFLAG_SAVE|CFGFLAG_CLIENT, "FSAA Samples") MACRO_CONFIG_INT(GfxRefreshRate, gfx_refresh_rate, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen refresh rate") MACRO_CONFIG_INT(GfxFinish, gfx_finish, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") +MACRO_CONFIG_INT(GfxAsyncRender, gfx_asyncrender, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Do rendering async from the the update") + +MACRO_CONFIG_INT(GfxThreaded, gfx_threaded, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use the threaded graphics backend") MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity") MACRO_CONFIG_STR(SvName, sv_name, 128, "unnamed server", CFGFLAG_SERVER, "Server name") -MACRO_CONFIG_STR(SvBindaddr, sv_bindaddr, 128, "", CFGFLAG_SERVER, "Address to bind the server to") +MACRO_CONFIG_STR(Bindaddr, bindaddr, 128, "", CFGFLAG_CLIENT|CFGFLAG_SERVER|CFGFLAG_MASTER, "Address to bind the client/server to") MACRO_CONFIG_INT(SvPort, sv_port, 8303, 0, 0, CFGFLAG_SERVER, "Port to use for the server") MACRO_CONFIG_INT(SvExternalPort, sv_external_port, 0, 0, 0, CFGFLAG_SERVER, "External port to report to the master servers") MACRO_CONFIG_STR(SvMap, sv_map, 128, "dm1", CFGFLAG_SERVER, "Map to use on the server") @@ -89,12 +94,12 @@ MACRO_CONFIG_INT(SvAutoDemoRecord, sv_auto_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos") MACRO_CONFIG_INT(SvAutoDemoMax, sv_auto_demo_max, 10, 0, 1000, CFGFLAG_SERVER, "Maximum number of automatically recorded demos (0 = no limit)") -MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_SERVER, "Address to bind the external console to. Anything but 'localhost' is dangerous") -MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_SERVER, "Port to use for the external console") -MACRO_CONFIG_STR(EcPassword, ec_password, 32, "", CFGFLAG_SERVER, "External console password") -MACRO_CONFIG_INT(EcBantime, ec_bantime, 0, 0, 1440, CFGFLAG_SERVER, "The time a client gets banned if econ authentication fails. 0 just closes the connection") -MACRO_CONFIG_INT(EcAuthTimeout, ec_auth_timeout, 30, 1, 120, CFGFLAG_SERVER, "Time in seconds before the the econ authentification times out") -MACRO_CONFIG_INT(EcOutputLevel, ec_output_level, 1, 0, 2, CFGFLAG_SERVER, "Adjusts the amount of information in the external console") +MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous") +MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_ECON, "Port to use for the external console") +MACRO_CONFIG_STR(EcPassword, ec_password, 32, "", CFGFLAG_ECON, "External console password") +MACRO_CONFIG_INT(EcBantime, ec_bantime, 0, 0, 1440, CFGFLAG_ECON, "The time a client gets banned if econ authentication fails. 0 just closes the connection") +MACRO_CONFIG_INT(EcAuthTimeout, ec_auth_timeout, 30, 1, 120, CFGFLAG_ECON, "Time in seconds before the the econ authentification times out") +MACRO_CONFIG_INT(EcOutputLevel, ec_output_level, 1, 0, 2, CFGFLAG_ECON, "Adjusts the amount of information in the external console") MACRO_CONFIG_INT(Debug, debug, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Debug mode") MACRO_CONFIG_INT(DbgStress, dbg_stress, 0, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Stress systems") diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/console.cpp teeworlds-0.6.2+dfsg/src/engine/shared/console.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/console.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/console.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -12,23 +12,25 @@ #include "console.h" #include "linereader.h" +// todo: rework this + const char *CConsole::CResult::GetString(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return ""; return m_apArgs[Index]; } int CConsole::CResult::GetInteger(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return 0; return str_toint(m_apArgs[Index]); } float CConsole::CResult::GetFloat(unsigned Index) { - if (Index < 0 || Index >= m_NumArgs) + if (Index >= m_NumArgs) return 0.0f; return str_tofloat(m_apArgs[Index]); } @@ -66,7 +68,7 @@ if(Length < Len) Len = Length; - str_copy(pResult->m_aStringStorage, pString, Length); + str_copy(pResult->m_aStringStorage, pString, Len); pStr = pResult->m_aStringStorage; // get command @@ -374,6 +376,14 @@ CConsole::ExecuteLineStroked(0, pStr); // then release it } +void CConsole::ExecuteLineFlag(const char *pStr, int FlagMask) +{ + int Temp = m_FlagMask; + m_FlagMask = FlagMask; + ExecuteLine(pStr); + m_FlagMask = Temp; +} + void CConsole::ExecuteFile(const char *pFilename) { @@ -564,6 +574,75 @@ } } +void CConsole::ConToggle(IConsole::IResult *pResult, void *pUser) +{ + CConsole* pConsole = static_cast(pUser); + char aBuf[128] = {0}; + CCommand *pCommand = pConsole->FindCommand(pResult->GetString(0), pConsole->m_FlagMask); + if(pCommand) + { + FCommandCallback pfnCallback = pCommand->m_pfnCallback; + void *pUserData = pCommand->m_pUserData; + + // check for chain + if(pCommand->m_pfnCallback == Con_Chain) + { + CChain *pChainInfo = static_cast(pCommand->m_pUserData); + pfnCallback = pChainInfo->m_pfnCallback; + pUserData = pChainInfo->m_pCallbackUserData; + } + + if(pfnCallback == IntVariableCommand) + { + CIntVariableData *pData = static_cast(pUserData); + int Val = *(pData->m_pVariable)==pResult->GetInteger(1) ? pResult->GetInteger(2) : pResult->GetInteger(1); + str_format(aBuf, sizeof(aBuf), "%s %i", pResult->GetString(0), Val); + pConsole->ExecuteLine(aBuf); + aBuf[0] = 0; + } + else + str_format(aBuf, sizeof(aBuf), "Invalid command: '%s'.", pResult->GetString(0)); + } + else + str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0)); + + if(aBuf[0] != 0) + pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); +} + +void CConsole::ConToggleStroke(IConsole::IResult *pResult, void *pUser) +{ + CConsole* pConsole = static_cast(pUser); + char aBuf[128] = {0}; + CCommand *pCommand = pConsole->FindCommand(pResult->GetString(1), pConsole->m_FlagMask); + if(pCommand) + { + FCommandCallback pfnCallback = pCommand->m_pfnCallback; + + // check for chain + if(pCommand->m_pfnCallback == Con_Chain) + { + CChain *pChainInfo = static_cast(pCommand->m_pUserData); + pfnCallback = pChainInfo->m_pfnCallback; + } + + if(pfnCallback == IntVariableCommand) + { + int Val = pResult->GetInteger(0)==0 ? pResult->GetInteger(3) : pResult->GetInteger(2); + str_format(aBuf, sizeof(aBuf), "%s %i", pResult->GetString(1), Val); + pConsole->ExecuteLine(aBuf); + aBuf[0] = 0; + } + else + str_format(aBuf, sizeof(aBuf), "Invalid command: '%s'.", pResult->GetString(1)); + } + else + str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(1)); + + if(aBuf[0] != 0) + pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); +} + CConsole::CConsole(int FlagMask) { m_FlagMask = FlagMask; @@ -585,6 +664,9 @@ Register("echo", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Echo, this, "Echo the text"); Register("exec", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Exec, this, "Execute the specified file"); + Register("toggle", "sii", CFGFLAG_SERVER|CFGFLAG_CLIENT, ConToggle, this, "Toggle config value"); + Register("+toggle", "sii", CFGFLAG_CLIENT, ConToggleStroke, this, "Toggle config value via keypress"); + Register("mod_command", "s?i", CFGFLAG_SERVER, ConModCommandAccess, this, "Specify command accessibility for moderators"); Register("mod_status", "", CFGFLAG_SERVER, ConModCommandStatus, this, "List all commands which are accessible for moderators"); @@ -633,7 +715,7 @@ void CConsole::AddCommandSorted(CCommand *pCommand) { - if(!m_pFirstCommand || str_comp(pCommand->m_pName, m_pFirstCommand->m_pName) < 0) + if(!m_pFirstCommand || str_comp(pCommand->m_pName, m_pFirstCommand->m_pName) <= 0) { if(m_pFirstCommand && m_pFirstCommand->m_pNext) pCommand->m_pNext = m_pFirstCommand; @@ -645,7 +727,7 @@ { for(CCommand *p = m_pFirstCommand; p; p = p->m_pNext) { - if(!p->m_pNext || str_comp(pCommand->m_pName, p->m_pNext->m_pName) < 0) + if(!p->m_pNext || str_comp(pCommand->m_pName, p->m_pNext->m_pName) <= 0) { pCommand->m_pNext = p->m_pNext; p->m_pNext = pCommand; @@ -658,18 +740,25 @@ void CConsole::Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) { - CCommand *pCommand = new(mem_alloc(sizeof(CCommand), sizeof(void*))) CCommand; + CCommand *pCommand = FindCommand(pName, Flags); + bool DoAdd = false; + if(pCommand == 0) + { + pCommand = new(mem_alloc(sizeof(CCommand), sizeof(void*))) CCommand; + DoAdd = true; + } pCommand->m_pfnCallback = pfnFunc; pCommand->m_pUserData = pUser; pCommand->m_pName = pName; pCommand->m_pHelp = pHelp; pCommand->m_pParams = pParams; - + pCommand->m_Flags = Flags; pCommand->m_Temp = false; - AddCommandSorted(pCommand); + if(DoAdd) + AddCommandSorted(pCommand); } void CConsole::RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp) @@ -699,7 +788,7 @@ } pCommand->m_pfnCallback = 0; - pCommand->m_pUserData = 0; + pCommand->m_pUserData = 0; pCommand->m_Flags = Flags; pCommand->m_Temp = true; @@ -729,7 +818,7 @@ break; } } - + // add to recycle list if(pRemoved) { @@ -742,7 +831,7 @@ { // set non temp as first one for(; m_pFirstCommand && m_pFirstCommand->m_Temp; m_pFirstCommand = m_pFirstCommand->m_pNext); - + // remove temp entries from command list for(CCommand *pCommand = m_pFirstCommand; pCommand && pCommand->m_pNext; pCommand = pCommand->m_pNext) { diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/console.h teeworlds-0.6.2+dfsg/src/engine/shared/console.h --- teeworlds-0.6.1+dfsg/src/engine/shared/console.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/console.h 2013-05-01 11:47:39.000000000 +0000 @@ -54,6 +54,8 @@ static void Con_Chain(IResult *pResult, void *pUserData); static void Con_Echo(IResult *pResult, void *pUserData); static void Con_Exec(IResult *pResult, void *pUserData); + static void ConToggle(IResult *pResult, void *pUser); + static void ConToggleStroke(IResult *pResult, void *pUser); static void ConModCommandAccess(IResult *pResult, void *pUser); static void ConModCommandStatus(IConsole::IResult *pResult, void *pUser); @@ -156,7 +158,7 @@ public: CConsole(int FlagMask); - virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const; + virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int FlagMask) const; virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp); virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser); @@ -170,6 +172,7 @@ virtual bool LineIsValid(const char *pStr); virtual void ExecuteLine(const char *pStr); + virtual void ExecuteLineFlag(const char *pStr, int FlagMask); virtual void ExecuteFile(const char *pFilename); virtual int RegisterPrintCallback(int OutputLevel, FPrintCallback pfnPrintCallback, void *pUserData); diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/demo.cpp teeworlds-0.6.2+dfsg/src/engine/shared/demo.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/demo.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/demo.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -13,8 +13,10 @@ #include "snapshot.h" static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0}; -static const unsigned char gs_ActVersion = 3; +static const unsigned char gs_ActVersion = 4; +static const unsigned char gs_OldVersion = 3; static const int gs_LengthOffset = 152; +static const int gs_NumMarkersOffset = 176; CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta) @@ -28,6 +30,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, unsigned Crc, const char *pType) { CDemoHeader Header; + CTimelineMarkers TimelineMarkers; if(m_File) return -1; @@ -90,6 +93,7 @@ // Header.m_Length - add this on stop str_timestamp(Header.m_aTimestamp, sizeof(Header.m_aTimestamp)); io_write(DemoFile, &Header, sizeof(Header)); + io_write(DemoFile, &TimelineMarkers, sizeof(TimelineMarkers)); // fill this on stop // write map data while(1) @@ -105,6 +109,7 @@ m_LastKeyFrame = -1; m_LastTickMarker = -1; m_FirstTick = -1; + m_NumTimelineMarkers = 0; char aBuf[256]; str_format(aBuf, sizeof(aBuf), "Recording to '%s'", pFilename); @@ -266,6 +271,25 @@ aLength[3] = (DemoLength)&0xff; io_write(m_File, aLength, sizeof(aLength)); + // add the timeline markers to the header + io_seek(m_File, gs_NumMarkersOffset, IOSEEK_START); + char aNumMarkers[4]; + aNumMarkers[0] = (m_NumTimelineMarkers>>24)&0xff; + aNumMarkers[1] = (m_NumTimelineMarkers>>16)&0xff; + aNumMarkers[2] = (m_NumTimelineMarkers>>8)&0xff; + aNumMarkers[3] = (m_NumTimelineMarkers)&0xff; + io_write(m_File, aNumMarkers, sizeof(aNumMarkers)); + for(int i = 0; i < m_NumTimelineMarkers; i++) + { + int Marker = m_aTimelineMarkers[i]; + char aMarker[4]; + aMarker[0] = (Marker>>24)&0xff; + aMarker[1] = (Marker>>16)&0xff; + aMarker[2] = (Marker>>8)&0xff; + aMarker[3] = (Marker)&0xff; + io_write(m_File, aMarker, sizeof(aMarker)); + } + io_close(m_File); m_File = 0; m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", "Stopped recording"); @@ -273,6 +297,24 @@ return 0; } +void CDemoRecorder::AddDemoMarker() +{ + if(m_LastTickMarker < 0 || m_NumTimelineMarkers >= MAX_TIMELINE_MARKERS) + return; + + // not more than 1 marker in a second + if(m_NumTimelineMarkers > 0) + { + int Diff = m_LastTickMarker - m_aTimelineMarkers[m_NumTimelineMarkers-1]; + if(Diff < SERVER_TICK_SPEED*1.0f) + return; + } + + m_aTimelineMarkers[m_NumTimelineMarkers++] = m_LastTickMarker; + + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", "Added timeline marker"); +} + CDemoPlayer::CDemoPlayer(class CSnapshotDelta *pSnapshotDelta) @@ -574,7 +616,7 @@ return -1; } - if(m_Info.m_Header.m_Version < gs_ActVersion) + if(m_Info.m_Header.m_Version < gs_OldVersion) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "demo version %d is not supported", m_Info.m_Header.m_Version); @@ -583,6 +625,8 @@ m_File = 0; return -1; } + else if(m_Info.m_Header.m_Version > gs_OldVersion) + io_read(m_File, &m_Info.m_TimelineMarkers, sizeof(m_Info.m_TimelineMarkers)); // get demo type if(!str_comp(m_Info.m_Header.m_aType, "client")) @@ -622,6 +666,19 @@ mem_free(pMapData); } + if(m_Info.m_Header.m_Version > gs_OldVersion) + { + // get timeline markers + int Num = ((m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[0]<<24)&0xFF000000) | ((m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[1]<<16)&0xFF0000) | + ((m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[2]<<8)&0xFF00) | (m_Info.m_TimelineMarkers.m_aNumTimelineMarkers[3]&0xFF); + m_Info.m_Info.m_NumTimelineMarkers = Num; + for(int i = 0; i < Num && i < MAX_TIMELINE_MARKERS; i++) + { + char *pTimelineMarker = m_Info.m_TimelineMarkers.m_aTimelineMarkers[i]; + m_Info.m_Info.m_aTimelineMarkers[i] = ((pTimelineMarker[0]<<24)&0xFF000000) | ((pTimelineMarker[1]<<16)&0xFF0000) | + ((pTimelineMarker[2]<<8)&0xFF00) | (pTimelineMarker[3]&0xFF); + } + } // scan the file for interessting points ScanFile(); @@ -775,7 +832,7 @@ else if(*pFileName == '.') pEnd = pFileName; } - + int Length = pEnd > pExtractedName ? min(BufferSize, (int)(pEnd-pExtractedName+1)) : BufferSize; str_copy(pBuffer, pExtractedName, Length); } @@ -792,7 +849,7 @@ return false; io_read(File, pDemoHeader, sizeof(CDemoHeader)); - if(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_ActVersion) + if(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_OldVersion) { io_close(File); return false; diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/demo.h teeworlds-0.6.2+dfsg/src/engine/shared/demo.h --- teeworlds-0.6.1+dfsg/src/engine/shared/demo.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/demo.h 2013-05-01 11:47:39.000000000 +0000 @@ -17,6 +17,8 @@ int m_FirstTick; unsigned char m_aLastSnapshotData[CSnapshot::MAX_SIZE]; class CSnapshotDelta *m_pSnapshotDelta; + int m_NumTimelineMarkers; + int m_aTimelineMarkers[MAX_TIMELINE_MARKERS]; void WriteTickMarker(int Tick, int Keyframe); void Write(int Type, const void *pData, int Size); @@ -25,6 +27,7 @@ int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, unsigned MapCrc, const char *pType); int Stop(); + void AddDemoMarker(); void RecordSnapshot(int Tick, const void *pData, int Size); void RecordMessage(const void *pData, int Size); @@ -48,6 +51,7 @@ struct CPlaybackInfo { CDemoHeader m_Header; + CTimelineMarkers m_TimelineMarkers; IDemoPlayer::CInfo m_Info; @@ -108,7 +112,7 @@ void Unpause(); int Stop(); void SetSpeed(float Speed); - int SetPos(float Precent); + int SetPos(float Percent); const CInfo *BaseInfo() const { return &m_Info.m_Info; } void GetDemoName(char *pBuffer, int BufferSize) const; bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader) const; diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/econ.cpp teeworlds-0.6.2+dfsg/src/engine/shared/econ.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/econ.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/econ.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -2,14 +2,15 @@ #include #include "econ.h" +#include "netban.h" + int CEcon::NewClientCallback(int ClientID, void *pUser) { CEcon *pThis = (CEcon *)pUser; - NETADDR Addr = pThis->m_NetConsole.ClientAddr(ClientID); char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(pThis->m_NetConsole.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true); char aBuf[128]; str_format(aBuf, sizeof(aBuf), "client accepted. cid=%d addr=%s'", ClientID, aAddrStr); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "econ", aBuf); @@ -26,9 +27,8 @@ { CEcon *pThis = (CEcon *)pUser; - NETADDR Addr = pThis->m_NetConsole.ClientAddr(ClientID); char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(pThis->m_NetConsole.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "client dropped. cid=%d addr=%s reason='%s'", ClientID, aAddrStr, pReason); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "econ", aBuf); @@ -52,7 +52,15 @@ } } -void CEcon::Init(IConsole *pConsole) +void CEcon::ConLogout(IConsole::IResult *pResult, void *pUserData) +{ + CEcon *pThis = static_cast(pUserData); + + if(pThis->m_UserClientID >= 0 && pThis->m_UserClientID < NET_MAX_CONSOLE_CLIENTS && pThis->m_aClients[pThis->m_UserClientID].m_State != CClient::STATE_EMPTY) + pThis->m_NetConsole.Drop(pThis->m_UserClientID, "Logout"); +} + +void CEcon::Init(IConsole *pConsole, CNetBan *pNetBan) { m_pConsole = pConsole; @@ -60,13 +68,18 @@ m_aClients[i].m_State = CClient::STATE_EMPTY; m_Ready = false; + m_UserClientID = -1; if(g_Config.m_EcPort == 0 || g_Config.m_EcPassword[0] == 0) return; NETADDR BindAddr; if(g_Config.m_EcBindaddr[0] && net_host_lookup(g_Config.m_EcBindaddr, &BindAddr, NETTYPE_ALL) == 0) + { + // got bindaddr + BindAddr.type = NETTYPE_ALL; BindAddr.port = g_Config.m_EcPort; + } else { mem_zero(&BindAddr, sizeof(BindAddr)); @@ -74,7 +87,7 @@ BindAddr.port = g_Config.m_EcPort; } - if(m_NetConsole.Open(BindAddr, 0)) + if(m_NetConsole.Open(BindAddr, pNetBan, 0)) { m_NetConsole.SetCallbacks(NewClientCallback, DelClientCallback, this); m_Ready = true; @@ -84,6 +97,8 @@ Console()->Chain("ec_output_level", ConchainEconOutputLevelUpdate, this); m_PrintCBIndex = Console()->RegisterPrintCallback(g_Config.m_EcOutputLevel, SendLineCB, this); + + Console()->Register("logout", "", CFGFLAG_ECON, ConLogout, this, "Logout of econ"); } else Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,"econ", "couldn't open socket. port might already be in use"); @@ -115,27 +130,26 @@ else { m_aClients[ClientID].m_AuthTries++; - char aBuf[128]; - str_format(aBuf, sizeof(aBuf), "Wrong password %d/%d.", m_aClients[ClientID].m_AuthTries, MAX_AUTH_TRIES); - m_NetConsole.Send(ClientID, aBuf); + char aMsg[128]; + str_format(aMsg, sizeof(aMsg), "Wrong password %d/%d.", m_aClients[ClientID].m_AuthTries, MAX_AUTH_TRIES); + m_NetConsole.Send(ClientID, aMsg); if(m_aClients[ClientID].m_AuthTries >= MAX_AUTH_TRIES) { if(!g_Config.m_EcBantime) m_NetConsole.Drop(ClientID, "Too many authentication tries"); else - { - NETADDR Addr = m_NetConsole.ClientAddr(ClientID); - m_NetConsole.AddBan(Addr, g_Config.m_EcBantime*60); - } + m_NetConsole.NetBan()->BanAddr(m_NetConsole.ClientAddr(ClientID), g_Config.m_EcBantime*60, "Too many authentication tries"); } } } else if(m_aClients[ClientID].m_State == CClient::STATE_AUTHED) { char aFormatted[256]; - str_format(aFormatted, sizeof(aBuf), "cid=%d cmd='%s'", ClientID, aBuf); + str_format(aFormatted, sizeof(aFormatted), "cid=%d cmd='%s'", ClientID, aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aFormatted); + m_UserClientID = ClientID; Console()->ExecuteLine(aBuf); + m_UserClientID = -1; } } diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/econ.h teeworlds-0.6.2+dfsg/src/engine/shared/econ.h --- teeworlds-0.6.1+dfsg/src/engine/shared/econ.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/econ.h 2013-05-01 11:47:39.000000000 +0000 @@ -3,6 +3,7 @@ #include "network.h" + class CEcon { enum @@ -31,9 +32,11 @@ bool m_Ready; int m_PrintCBIndex; + int m_UserClientID; static void SendLineCB(const char *pLine, void *pUserData); static void ConchainEconOutputLevelUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); + static void ConLogout(IConsole::IResult *pResult, void *pUserData); static int NewClientCallback(int ClientID, void *pUser); static int DelClientCallback(int ClientID, const char *pReason, void *pUser); @@ -41,7 +44,7 @@ public: IConsole *Console() { return m_pConsole; } - void Init(IConsole *pConsole); + void Init(IConsole *pConsole, class CNetBan *pNetBan); void Update(); void Send(int ClientID, const char *pLine); void Shutdown(); diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/mapchecker.cpp teeworlds-0.6.2+dfsg/src/engine/shared/mapchecker.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/mapchecker.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/mapchecker.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -6,6 +6,7 @@ #include #include +#include #include "datafile.h" #include "memheap.h" diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/masterserver.cpp teeworlds-0.6.2+dfsg/src/engine/shared/masterserver.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/masterserver.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/masterserver.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -157,7 +157,7 @@ Added = true; break; } - + if(!Added) { for(int i = 0; i < MAX_MASTERSERVERS; ++i) @@ -192,13 +192,13 @@ { char aAddrStr[NETADDR_MAXSTRSIZE]; if(m_aMasterServers[i].m_Addr.type != NETTYPE_INVALID) - net_addr_str(&m_aMasterServers[i].m_Addr, aAddrStr, sizeof(aAddrStr)); + net_addr_str(&m_aMasterServers[i].m_Addr, aAddrStr, sizeof(aAddrStr), true); else aAddrStr[0] = 0; char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "%s %s\n", m_aMasterServers[i].m_aHostname, aAddrStr); - + str_format(aBuf, sizeof(aBuf), "%s %s", m_aMasterServers[i].m_aHostname, aAddrStr); io_write(File, aBuf, str_length(aBuf)); + io_write_newline(File); } io_close(File); diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/netban.cpp teeworlds-0.6.2+dfsg/src/engine/shared/netban.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/netban.cpp 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/netban.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,603 @@ +#include + +#include +#include +#include + +#include "netban.h" + + +bool CNetBan::StrAllnum(const char *pStr) +{ + while(*pStr) + { + if(!(*pStr >= '0' && *pStr <= '9')) + return false; + pStr++; + } + return true; +} + + +CNetBan::CNetHash::CNetHash(const NETADDR *pAddr) +{ + if(pAddr->type==NETTYPE_IPV4) + m_Hash = (pAddr->ip[0]+pAddr->ip[1]+pAddr->ip[2]+pAddr->ip[3])&0xFF; + else + m_Hash = (pAddr->ip[0]+pAddr->ip[1]+pAddr->ip[2]+pAddr->ip[3]+pAddr->ip[4]+pAddr->ip[5]+pAddr->ip[6]+pAddr->ip[7]+ + pAddr->ip[8]+pAddr->ip[9]+pAddr->ip[10]+pAddr->ip[11]+pAddr->ip[12]+pAddr->ip[13]+pAddr->ip[14]+pAddr->ip[15])&0xFF; + m_HashIndex = 0; +} + +CNetBan::CNetHash::CNetHash(const CNetRange *pRange) +{ + m_Hash = 0; + m_HashIndex = 0; + for(int i = 0; pRange->m_LB.ip[i] == pRange->m_UB.ip[i]; ++i) + { + m_Hash += pRange->m_LB.ip[i]; + ++m_HashIndex; + } + m_Hash &= 0xFF; +} + +int CNetBan::CNetHash::MakeHashArray(const NETADDR *pAddr, CNetHash aHash[17]) +{ + int Length = pAddr->type==NETTYPE_IPV4 ? 4 : 16; + aHash[0].m_Hash = 0; + aHash[0].m_HashIndex = 0; + for(int i = 1, Sum = 0; i <= Length; ++i) + { + Sum += pAddr->ip[i-1]; + aHash[i].m_Hash = Sum&0xFF; + aHash[i].m_HashIndex = i%Length; + } + return Length; +} + + +template +typename CNetBan::CBan *CNetBan::CBanPool::Add(const T *pData, const CBanInfo *pInfo, const CNetHash *pNetHash) +{ + if(!m_pFirstFree) + return 0; + + // create new ban + CBan *pBan = m_pFirstFree; + pBan->m_Data = *pData; + pBan->m_Info = *pInfo; + pBan->m_NetHash = *pNetHash; + if(pBan->m_pNext) + pBan->m_pNext->m_pPrev = pBan->m_pPrev; + if(pBan->m_pPrev) + pBan->m_pPrev->m_pNext = pBan->m_pNext; + else + m_pFirstFree = pBan->m_pNext; + + // add it to the hash list + if(m_paaHashList[pNetHash->m_HashIndex][pNetHash->m_Hash]) + m_paaHashList[pNetHash->m_HashIndex][pNetHash->m_Hash]->m_pHashPrev = pBan; + pBan->m_pHashPrev = 0; + pBan->m_pHashNext = m_paaHashList[pNetHash->m_HashIndex][pNetHash->m_Hash]; + m_paaHashList[pNetHash->m_HashIndex][pNetHash->m_Hash] = pBan; + + // insert it into the used list + if(m_pFirstUsed) + { + for(CBan *p = m_pFirstUsed; ; p = p->m_pNext) + { + if(p->m_Info.m_Expires == CBanInfo::EXPIRES_NEVER || (pInfo->m_Expires != CBanInfo::EXPIRES_NEVER && pInfo->m_Expires <= p->m_Info.m_Expires)) + { + // insert before + pBan->m_pNext = p; + pBan->m_pPrev = p->m_pPrev; + if(p->m_pPrev) + p->m_pPrev->m_pNext = pBan; + else + m_pFirstUsed = pBan; + p->m_pPrev = pBan; + break; + } + + if(!p->m_pNext) + { + // last entry + p->m_pNext = pBan; + pBan->m_pPrev = p; + pBan->m_pNext = 0; + break; + } + } + } + else + { + m_pFirstUsed = pBan; + pBan->m_pNext = pBan->m_pPrev = 0; + } + + // update ban count + ++m_CountUsed; + + return pBan; +} + +template +int CNetBan::CBanPool::Remove(CBan *pBan) +{ + if(pBan == 0) + return -1; + + // remove from hash list + if(pBan->m_pHashNext) + pBan->m_pHashNext->m_pHashPrev = pBan->m_pHashPrev; + if(pBan->m_pHashPrev) + pBan->m_pHashPrev->m_pHashNext = pBan->m_pHashNext; + else + m_paaHashList[pBan->m_NetHash.m_HashIndex][pBan->m_NetHash.m_Hash] = pBan->m_pHashNext; + pBan->m_pHashNext = pBan->m_pHashPrev = 0; + + // remove from used list + if(pBan->m_pNext) + pBan->m_pNext->m_pPrev = pBan->m_pPrev; + if(pBan->m_pPrev) + pBan->m_pPrev->m_pNext = pBan->m_pNext; + else + m_pFirstUsed = pBan->m_pNext; + + // add to recycle list + if(m_pFirstFree) + m_pFirstFree->m_pPrev = pBan; + pBan->m_pPrev = 0; + pBan->m_pNext = m_pFirstFree; + m_pFirstFree = pBan; + + // update ban count + --m_CountUsed; + + return 0; +} + +template +void CNetBan::CBanPool::Update(CBan *pBan, const CBanInfo *pInfo) +{ + pBan->m_Info = *pInfo; + + // remove from used list + if(pBan->m_pNext) + pBan->m_pNext->m_pPrev = pBan->m_pPrev; + if(pBan->m_pPrev) + pBan->m_pPrev->m_pNext = pBan->m_pNext; + else + m_pFirstUsed = pBan->m_pNext; + + // insert it into the used list + if(m_pFirstUsed) + { + for(CBan *p = m_pFirstUsed; ; p = p->m_pNext) + { + if(p->m_Info.m_Expires == CBanInfo::EXPIRES_NEVER || (pInfo->m_Expires != CBanInfo::EXPIRES_NEVER && pInfo->m_Expires <= p->m_Info.m_Expires)) + { + // insert before + pBan->m_pNext = p; + pBan->m_pPrev = p->m_pPrev; + if(p->m_pPrev) + p->m_pPrev->m_pNext = pBan; + else + m_pFirstUsed = pBan; + p->m_pPrev = pBan; + break; + } + + if(!p->m_pNext) + { + // last entry + p->m_pNext = pBan; + pBan->m_pPrev = p; + pBan->m_pNext = 0; + break; + } + } + } + else + { + m_pFirstUsed = pBan; + pBan->m_pNext = pBan->m_pPrev = 0; + } +} + +template +void CNetBan::CBanPool::Reset() +{ + mem_zero(m_paaHashList, sizeof(m_paaHashList)); + mem_zero(m_aBans, sizeof(m_aBans)); + m_pFirstUsed = 0; + m_CountUsed = 0; + + for(int i = 1; i < MAX_BANS-1; ++i) + { + m_aBans[i].m_pNext = &m_aBans[i+1]; + m_aBans[i].m_pPrev = &m_aBans[i-1]; + } + + m_aBans[0].m_pNext = &m_aBans[1]; + m_aBans[MAX_BANS-1].m_pPrev = &m_aBans[MAX_BANS-2]; + m_pFirstFree = &m_aBans[0]; +} + +template +typename CNetBan::CBan *CNetBan::CBanPool::Get(int Index) const +{ + if(Index < 0 || Index >= Num()) + return 0; + + for(CNetBan::CBan *pBan = m_pFirstUsed; pBan; pBan = pBan->m_pNext, --Index) + { + if(Index == 0) + return pBan; + } + + return 0; +} + + +template +void CNetBan::MakeBanInfo(const CBan *pBan, char *pBuf, unsigned BuffSize, int Type) const +{ + if(pBan == 0 || pBuf == 0) + { + if(BuffSize > 0) + pBuf[0] = 0; + return; + } + + // build type based part + char aBuf[256]; + if(Type == MSGTYPE_PLAYER) + str_copy(aBuf, "You have been banned", sizeof(aBuf)); + else + { + char aTemp[256]; + switch(Type) + { + case MSGTYPE_LIST: + str_format(aBuf, sizeof(aBuf), "%s banned", NetToString(&pBan->m_Data, aTemp, sizeof(aTemp))); break; + case MSGTYPE_BANADD: + str_format(aBuf, sizeof(aBuf), "banned %s", NetToString(&pBan->m_Data, aTemp, sizeof(aTemp))); break; + case MSGTYPE_BANREM: + str_format(aBuf, sizeof(aBuf), "unbanned %s", NetToString(&pBan->m_Data, aTemp, sizeof(aTemp))); break; + default: + aBuf[0] = 0; + } + } + + // add info part + if(pBan->m_Info.m_Expires != CBanInfo::EXPIRES_NEVER) + { + int Mins = ((pBan->m_Info.m_Expires-time_timestamp()) + 59) / 60; + if(Mins <= 1) + str_format(pBuf, BuffSize, "%s for 1 minute (%s)", aBuf, pBan->m_Info.m_aReason); + else + str_format(pBuf, BuffSize, "%s for %d minutes (%s)", aBuf, Mins, pBan->m_Info.m_aReason); + } + else + str_format(pBuf, BuffSize, "%s for life (%s)", aBuf, pBan->m_Info.m_aReason); +} + +template +int CNetBan::Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason) +{ + // do not ban localhost + if(NetMatch(pData, &m_LocalhostIPV4) || NetMatch(pData, &m_LocalhostIPV6)) + { + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (localhost)"); + return -1; + } + + int Stamp = Seconds > 0 ? time_timestamp()+Seconds : CBanInfo::EXPIRES_NEVER; + + // set up info + CBanInfo Info = {0}; + Info.m_Expires = Stamp; + str_copy(Info.m_aReason, pReason, sizeof(Info.m_aReason)); + + // check if it already exists + CNetHash NetHash(pData); + CBan *pBan = pBanPool->Find(pData, &NetHash); + if(pBan) + { + // adjust the ban + pBanPool->Update(pBan, &Info); + char aBuf[128]; + MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_LIST); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); + return 1; + } + + // add ban and print result + pBan = pBanPool->Add(pData, &Info, &NetHash); + if(pBan) + { + char aBuf[128]; + MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_BANADD); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); + return 0; + } + else + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (full banlist)"); + return -1; +} + +template +int CNetBan::Unban(T *pBanPool, const typename T::CDataType *pData) +{ + CNetHash NetHash(pData); + CBan *pBan = pBanPool->Find(pData, &NetHash); + if(pBan) + { + char aBuf[256]; + MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_BANREM); + pBanPool->Remove(pBan); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); + return 0; + } + else + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "unban failed (invalid entry)"); + return -1; +} + +void CNetBan::Init(IConsole *pConsole, IStorage *pStorage) +{ + m_pConsole = pConsole; + m_pStorage = pStorage; + m_BanAddrPool.Reset(); + m_BanRangePool.Reset(); + + net_host_lookup("localhost", &m_LocalhostIPV4, NETTYPE_IPV4); + net_host_lookup("localhost", &m_LocalhostIPV6, NETTYPE_IPV6); + + Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_MASTER|CFGFLAG_STORE, ConBan, this, "Ban ip for x minutes for any reason"); + Console()->Register("ban_range", "ss?ir", CFGFLAG_SERVER|CFGFLAG_MASTER|CFGFLAG_STORE, ConBanRange, this, "Ban ip range for x minutes for any reason"); + Console()->Register("unban", "s", CFGFLAG_SERVER|CFGFLAG_MASTER|CFGFLAG_STORE, ConUnban, this, "Unban ip/banlist entry"); + Console()->Register("unban_range", "ss", CFGFLAG_SERVER|CFGFLAG_MASTER|CFGFLAG_STORE, ConUnbanRange, this, "Unban ip range"); + Console()->Register("unban_all", "", CFGFLAG_SERVER|CFGFLAG_MASTER|CFGFLAG_STORE, ConUnbanAll, this, "Unban all entries"); + Console()->Register("bans", "", CFGFLAG_SERVER|CFGFLAG_MASTER|CFGFLAG_STORE, ConBans, this, "Show banlist"); + Console()->Register("bans_save", "s", CFGFLAG_SERVER|CFGFLAG_MASTER|CFGFLAG_STORE, ConBansSave, this, "Save banlist in a file"); +} + +void CNetBan::Update() +{ + int Now = time_timestamp(); + + // remove expired bans + char aBuf[256], aNetStr[256]; + while(m_BanAddrPool.First() && m_BanAddrPool.First()->m_Info.m_Expires != CBanInfo::EXPIRES_NEVER && m_BanAddrPool.First()->m_Info.m_Expires < Now) + { + str_format(aBuf, sizeof(aBuf), "ban %s expired", NetToString(&m_BanAddrPool.First()->m_Data, aNetStr, sizeof(aNetStr))); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); + m_BanAddrPool.Remove(m_BanAddrPool.First()); + } + while(m_BanRangePool.First() && m_BanRangePool.First()->m_Info.m_Expires != CBanInfo::EXPIRES_NEVER && m_BanRangePool.First()->m_Info.m_Expires < Now) + { + str_format(aBuf, sizeof(aBuf), "ban %s expired", NetToString(&m_BanRangePool.First()->m_Data, aNetStr, sizeof(aNetStr))); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); + m_BanRangePool.Remove(m_BanRangePool.First()); + } +} + +int CNetBan::BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason) +{ + return Ban(&m_BanAddrPool, pAddr, Seconds, pReason); +} + +int CNetBan::BanRange(const CNetRange *pRange, int Seconds, const char *pReason) +{ + if(pRange->IsValid()) + return Ban(&m_BanRangePool, pRange, Seconds, pReason); + + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (invalid range)"); + return -1; +} + +int CNetBan::UnbanByAddr(const NETADDR *pAddr) +{ + return Unban(&m_BanAddrPool, pAddr); +} + +int CNetBan::UnbanByRange(const CNetRange *pRange) +{ + if(pRange->IsValid()) + return Unban(&m_BanRangePool, pRange); + + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (invalid range)"); + return -1; +} + +int CNetBan::UnbanByIndex(int Index) +{ + int Result; + char aBuf[256]; + CBanAddr *pBan = m_BanAddrPool.Get(Index); + if(pBan) + { + NetToString(&pBan->m_Data, aBuf, sizeof(aBuf)); + Result = m_BanAddrPool.Remove(pBan); + } + else + { + CBanRange *pBan = m_BanRangePool.Get(Index-m_BanAddrPool.Num()); + if(pBan) + { + NetToString(&pBan->m_Data, aBuf, sizeof(aBuf)); + Result = m_BanRangePool.Remove(pBan); + } + else + { + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "unban failed (invalid index)"); + return -1; + } + } + + char aMsg[256]; + str_format(aMsg, sizeof(aMsg), "unbanned index %i (%s)", Index, aBuf); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg); + return Result; +} + +bool CNetBan::IsBanned(const NETADDR *pAddr, char *pBuf, unsigned BufferSize) const +{ + CNetHash aHash[17]; + int Length = CNetHash::MakeHashArray(pAddr, aHash); + + // check ban adresses + CBanAddr *pBan = m_BanAddrPool.Find(pAddr, &aHash[Length]); + if(pBan) + { + MakeBanInfo(pBan, pBuf, BufferSize, MSGTYPE_PLAYER); + return true; + } + + // check ban ranges + for(int i = Length-1; i >= 0; --i) + { + for(CBanRange *pBan = m_BanRangePool.First(&aHash[i]); pBan; pBan = pBan->m_pHashNext) + { + if(NetMatch(&pBan->m_Data, pAddr, i, Length)) + { + MakeBanInfo(pBan, pBuf, BufferSize, MSGTYPE_PLAYER); + return true; + } + } + } + + return false; +} + +void CNetBan::ConBan(IConsole::IResult *pResult, void *pUser) +{ + CNetBan *pThis = static_cast(pUser); + + const char *pStr = pResult->GetString(0); + int Minutes = pResult->NumArguments()>1 ? clamp(pResult->GetInteger(1), 0, 44640) : 30; + const char *pReason = pResult->NumArguments()>2 ? pResult->GetString(2) : "No reason given"; + + NETADDR Addr; + if(net_addr_from_str(&Addr, pStr) == 0) + pThis->BanAddr(&Addr, Minutes*60, pReason); + else + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid network address)"); +} + +void CNetBan::ConBanRange(IConsole::IResult *pResult, void *pUser) +{ + CNetBan *pThis = static_cast(pUser); + + const char *pStr1 = pResult->GetString(0); + const char *pStr2 = pResult->GetString(1); + int Minutes = pResult->NumArguments()>2 ? clamp(pResult->GetInteger(2), 0, 44640) : 30; + const char *pReason = pResult->NumArguments()>3 ? pResult->GetString(3) : "No reason given"; + + CNetRange Range; + if(net_addr_from_str(&Range.m_LB, pStr1) == 0 && net_addr_from_str(&Range.m_UB, pStr2) == 0) + pThis->BanRange(&Range, Minutes*60, pReason); + else + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid range)"); +} + +void CNetBan::ConUnban(IConsole::IResult *pResult, void *pUser) +{ + CNetBan *pThis = static_cast(pUser); + + const char *pStr = pResult->GetString(0); + if(StrAllnum(pStr)) + pThis->UnbanByIndex(str_toint(pStr)); + else + { + NETADDR Addr; + if(net_addr_from_str(&Addr, pStr) == 0) + pThis->UnbanByAddr(&Addr); + else + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "unban error (invalid network address)"); + } +} + +void CNetBan::ConUnbanRange(IConsole::IResult *pResult, void *pUser) +{ + CNetBan *pThis = static_cast(pUser); + + const char *pStr1 = pResult->GetString(0); + const char *pStr2 = pResult->GetString(1); + + CNetRange Range; + if(net_addr_from_str(&Range.m_LB, pStr1) == 0 && net_addr_from_str(&Range.m_UB, pStr2) == 0) + pThis->UnbanByRange(&Range); + else + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "unban error (invalid range)"); +} + +void CNetBan::ConUnbanAll(IConsole::IResult *pResult, void *pUser) +{ + CNetBan *pThis = static_cast(pUser); + + pThis->UnbanAll(); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "unbanned all entries"); +} + +void CNetBan::ConBans(IConsole::IResult *pResult, void *pUser) +{ + CNetBan *pThis = static_cast(pUser); + + int Count = 0; + char aBuf[256], aMsg[256]; + for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext) + { + pThis->MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_LIST); + str_format(aMsg, sizeof(aMsg), "#%i %s", Count++, aBuf); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg); + } + for(CBanRange *pBan = pThis->m_BanRangePool.First(); pBan; pBan = pBan->m_pNext) + { + pThis->MakeBanInfo(pBan, aBuf, sizeof(aBuf), MSGTYPE_LIST); + str_format(aMsg, sizeof(aMsg), "#%i %s", Count++, aBuf); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg); + } + str_format(aMsg, sizeof(aMsg), "%d %s", Count, Count==1?"ban":"bans"); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aMsg); +} + +void CNetBan::ConBansSave(IConsole::IResult *pResult, void *pUser) +{ + CNetBan *pThis = static_cast(pUser); + + char aBuf[256]; + IOHANDLE File = pThis->Storage()->OpenFile(pResult->GetString(0), IOFLAG_WRITE, IStorage::TYPE_SAVE); + if(!File) + { + str_format(aBuf, sizeof(aBuf), "failed to save banlist to '%s'", pResult->GetString(0)); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); + return; + } + + int Now = time_timestamp(); + char aAddrStr1[NETADDR_MAXSTRSIZE], aAddrStr2[NETADDR_MAXSTRSIZE]; + for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext) + { + int Min = pBan->m_Info.m_Expires>-1 ? (pBan->m_Info.m_Expires-Now+59)/60 : -1; + net_addr_str(&pBan->m_Data, aAddrStr1, sizeof(aAddrStr1), false); + str_format(aBuf, sizeof(aBuf), "ban %s %i %s", aAddrStr1, Min, pBan->m_Info.m_aReason); + io_write(File, aBuf, str_length(aBuf)); + io_write_newline(File); + } + for(CBanRange *pBan = pThis->m_BanRangePool.First(); pBan; pBan = pBan->m_pNext) + { + int Min = pBan->m_Info.m_Expires>-1 ? (pBan->m_Info.m_Expires-Now+59)/60 : -1; + net_addr_str(&pBan->m_Data.m_LB, aAddrStr1, sizeof(aAddrStr1), false); + net_addr_str(&pBan->m_Data.m_UB, aAddrStr2, sizeof(aAddrStr2), false); + str_format(aBuf, sizeof(aBuf), "ban_range %s %s %i %s", aAddrStr1, aAddrStr2, Min, pBan->m_Info.m_aReason); + io_write(File, aBuf, str_length(aBuf)); + io_write_newline(File); + } + + io_close(File); + str_format(aBuf, sizeof(aBuf), "saved banlist to '%s'", pResult->GetString(0)); + pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", aBuf); +} diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/netban.h teeworlds-0.6.2+dfsg/src/engine/shared/netban.h --- teeworlds-0.6.1+dfsg/src/engine/shared/netban.h 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/netban.h 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,193 @@ +#ifndef ENGINE_SHARED_NETBAN_H +#define ENGINE_SHARED_NETBAN_H + +#include + + +inline int NetComp(const NETADDR *pAddr1, const NETADDR *pAddr2) +{ + return mem_comp(pAddr1, pAddr2, pAddr1->type==NETTYPE_IPV4 ? 8 : 20); +} + +class CNetRange +{ +public: + NETADDR m_LB; + NETADDR m_UB; + + bool IsValid() const { return m_LB.type == m_UB.type && NetComp(&m_LB, &m_UB) < 0; } +}; + +inline int NetComp(const CNetRange *pRange1, const CNetRange *pRange2) +{ + return NetComp(&pRange1->m_LB, &pRange2->m_LB) || NetComp(&pRange1->m_UB, &pRange2->m_UB); +} + + +class CNetBan +{ +protected: + bool NetMatch(const NETADDR *pAddr1, const NETADDR *pAddr2) const + { + return NetComp(pAddr1, pAddr2) == 0; + } + + bool NetMatch(const CNetRange *pRange, const NETADDR *pAddr, int Start, int Length) const + { + return pRange->m_LB.type == pAddr->type && (Start == 0 || mem_comp(&pRange->m_LB.ip[0], &pAddr->ip[0], Start) == 0) && + mem_comp(&pRange->m_LB.ip[Start], &pAddr->ip[Start], Length-Start) <= 0 && mem_comp(&pRange->m_UB.ip[Start], &pAddr->ip[Start], Length-Start) >= 0; + } + + bool NetMatch(const CNetRange *pRange, const NETADDR *pAddr) const + { + return NetMatch(pRange, pAddr, 0, pRange->m_LB.type==NETTYPE_IPV4 ? 4 : 16); + } + + const char *NetToString(const NETADDR *pData, char *pBuffer, unsigned BufferSize) const + { + char aAddrStr[NETADDR_MAXSTRSIZE]; + net_addr_str(pData, aAddrStr, sizeof(aAddrStr), false); + str_format(pBuffer, BufferSize, "'%s'", aAddrStr); + return pBuffer; + } + + const char *NetToString(const CNetRange *pData, char *pBuffer, unsigned BufferSize) const + { + char aAddrStr1[NETADDR_MAXSTRSIZE], aAddrStr2[NETADDR_MAXSTRSIZE]; + net_addr_str(&pData->m_LB, aAddrStr1, sizeof(aAddrStr1), false); + net_addr_str(&pData->m_UB, aAddrStr2, sizeof(aAddrStr2), false); + str_format(pBuffer, BufferSize, "'%s' - '%s'", aAddrStr1, aAddrStr2); + return pBuffer; + } + + // todo: move? + static bool StrAllnum(const char *pStr); + + class CNetHash + { + public: + int m_Hash; + int m_HashIndex; // matching parts for ranges, 0 for addr + + CNetHash() {} + CNetHash(const NETADDR *pAddr); + CNetHash(const CNetRange *pRange); + + static int MakeHashArray(const NETADDR *pAddr, CNetHash aHash[17]); + }; + + struct CBanInfo + { + enum + { + EXPIRES_NEVER=-1, + REASON_LENGTH=64, + }; + int m_Expires; + char m_aReason[REASON_LENGTH]; + }; + + template struct CBan + { + T m_Data; + CBanInfo m_Info; + CNetHash m_NetHash; + + // hash list + CBan *m_pHashNext; + CBan *m_pHashPrev; + + // used or free list + CBan *m_pNext; + CBan *m_pPrev; + }; + + template class CBanPool + { + public: + typedef T CDataType; + + CBan *Add(const CDataType *pData, const CBanInfo *pInfo, const CNetHash *pNetHash); + int Remove(CBan *pBan); + void Update(CBan *pBan, const CBanInfo *pInfo); + void Reset(); + + int Num() const { return m_CountUsed; } + bool IsFull() const { return m_CountUsed == MAX_BANS; } + + CBan *First() const { return m_pFirstUsed; } + CBan *First(const CNetHash *pNetHash) const { return m_paaHashList[pNetHash->m_HashIndex][pNetHash->m_Hash]; } + CBan *Find(const CDataType *pData, const CNetHash *pNetHash) const + { + for(CBan *pBan = m_paaHashList[pNetHash->m_HashIndex][pNetHash->m_Hash]; pBan; pBan = pBan->m_pHashNext) + { + if(NetComp(&pBan->m_Data, pData) == 0) + return pBan; + } + + return 0; + } + CBan *Get(int Index) const; + + private: + enum + { + MAX_BANS=1024, + }; + + CBan *m_paaHashList[HashCount][256]; + CBan m_aBans[MAX_BANS]; + CBan *m_pFirstFree; + CBan *m_pFirstUsed; + int m_CountUsed; + }; + + typedef CBanPool CBanAddrPool; + typedef CBanPool CBanRangePool; + typedef CBan CBanAddr; + typedef CBan CBanRange; + + template void MakeBanInfo(const CBan *pBan, char *pBuf, unsigned BuffSize, int Type) const; + template int Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason); + template int Unban(T *pBanPool, const typename T::CDataType *pData); + + class IConsole *m_pConsole; + class IStorage *m_pStorage; + CBanAddrPool m_BanAddrPool; + CBanRangePool m_BanRangePool; + NETADDR m_LocalhostIPV4, m_LocalhostIPV6; + +public: + enum + { + MSGTYPE_PLAYER=0, + MSGTYPE_LIST, + MSGTYPE_BANADD, + MSGTYPE_BANREM, + }; + + class IConsole *Console() const { return m_pConsole; } + class IStorage *Storage() const { return m_pStorage; } + + virtual ~CNetBan() {} + void Init(class IConsole *pConsole, class IStorage *pStorage); + void Update(); + + virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); + virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); + int UnbanByAddr(const NETADDR *pAddr); + int UnbanByRange(const CNetRange *pRange); + int UnbanByIndex(int Index); + void UnbanAll() { m_BanAddrPool.Reset(); m_BanRangePool.Reset(); } + bool IsBanned(const NETADDR *pAddr, char *pBuf, unsigned BufferSize) const; + + static void ConBan(class IConsole::IResult *pResult, void *pUser); + static void ConBanRange(class IConsole::IResult *pResult, void *pUser); + static void ConUnban(class IConsole::IResult *pResult, void *pUser); + static void ConUnbanRange(class IConsole::IResult *pResult, void *pUser); + static void ConUnbanAll(class IConsole::IResult *pResult, void *pUser); + static void ConBans(class IConsole::IResult *pResult, void *pUser); + static void ConBansSave(class IConsole::IResult *pResult, void *pUser); +}; + +#endif diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/network.h teeworlds-0.6.2+dfsg/src/engine/shared/network.h --- teeworlds-0.6.1+dfsg/src/engine/shared/network.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/network.h 2013-05-01 11:47:39.000000000 +0000 @@ -73,8 +73,6 @@ NET_CTRLMSG_ACCEPT=3, NET_CTRLMSG_CLOSE=4, - NET_SERVER_MAXBANS=1024, - NET_CONN_BUFFERSIZE=1024*32, NET_ENUM_TERMINATOR @@ -142,6 +140,7 @@ int m_Token; int m_RemoteClosed; + bool m_BlockCloseMsg; TStaticRingBuffer m_Buffer; @@ -169,7 +168,7 @@ void Resend(); public: - void Init(NETSOCKET Socket); + void Init(NETSOCKET Socket, bool BlockCloseMsg); int Connect(NETADDR *pAddr); void Disconnect(const char *pReason); @@ -182,13 +181,14 @@ const char *ErrorString(); void SignalResend(); int State() const { return m_State; } - NETADDR PeerAddress() const { return m_PeerAddr; } + const NETADDR *PeerAddress() const { return &m_PeerAddr; } void ResetErrorString() { m_ErrorString[0] = 0; } const char *ErrorString() const { return m_ErrorString; } // Needed for GotProblems in NetClient int64 LastRecvTime() const { return m_LastRecvTime; } + int64 ConnectTime() const { return m_LastUpdateTime; } int AckSequence() const { return m_Ack; } }; @@ -214,7 +214,7 @@ void Disconnect(const char *pReason); int State() const { return m_State; } - NETADDR PeerAddress() const { return m_PeerAddr; } + const NETADDR *PeerAddress() const { return &m_PeerAddr; } const char *ErrorString() const { return m_aErrorString; } void Reset(); @@ -244,59 +244,29 @@ // server side class CNetServer { -public: - struct CBanInfo - { - NETADDR m_Addr; - int m_Expires; - char m_Reason[128]; - }; - -private: struct CSlot { public: CNetConnection m_Connection; }; - struct CBan - { - public: - CBanInfo m_Info; - - // hash list - CBan *m_pHashNext; - CBan *m_pHashPrev; - - // used or free list - CBan *m_pNext; - CBan *m_pPrev; - }; - - NETSOCKET m_Socket; + class CNetBan *m_pNetBan; CSlot m_aSlots[NET_MAX_CLIENTS]; int m_MaxClients; int m_MaxClientsPerIP; - CBan *m_aBans[256]; - CBan m_BanPool[NET_SERVER_MAXBANS]; - CBan *m_BanPool_FirstFree; - CBan *m_BanPool_FirstUsed; - NETFUNC_NEWCLIENT m_pfnNewClient; NETFUNC_DELCLIENT m_pfnDelClient; void *m_UserPtr; CNetRecvUnpacker m_RecvUnpacker; - void BanRemoveByObject(CBan *pBan); - public: int SetCallbacks(NETFUNC_NEWCLIENT pfnNewClient, NETFUNC_DELCLIENT pfnDelClient, void *pUser); // - bool Open(NETADDR BindAddr, int MaxClients, int MaxClientsPerIP, int Flags); + bool Open(NETADDR BindAddr, class CNetBan *pNetBan, int MaxClients, int MaxClientsPerIP, int Flags); int Close(); // @@ -307,16 +277,11 @@ // int Drop(int ClientID, const char *pReason); - // banning - int BanAdd(NETADDR Addr, int Seconds, const char *pReason); - int BanRemove(NETADDR Addr); - int BanNum(); // caution, slow - int BanGet(int Index, CBanInfo *pInfo); // caution, slow - // status requests - NETADDR ClientAddr(int ClientID) const { return m_aSlots[ClientID].m_Connection.PeerAddress(); } + const NETADDR *ClientAddr(int ClientID) const { return m_aSlots[ClientID].m_Connection.PeerAddress(); } NETSOCKET Socket() const { return m_Socket; } - int NetType() { return m_Socket.type; } + class CNetBan *NetBan() const { return m_pNetBan; } + int NetType() const { return m_Socket.type; } int MaxClients() const { return m_MaxClients; } // @@ -325,27 +290,13 @@ class CNetConsole { - enum - { - MAX_BANS=128, - }; - - int FindBan(NETADDR Addr); - void UpdateBans(); - - struct CBanEntry - { - NETADDR m_Addr; - int m_Expires; - } m_aBans[MAX_BANS]; - int m_NumBans; - struct CSlot { CConsoleNetConnection m_Connection; }; NETSOCKET m_Socket; + class CNetBan *m_pNetBan; CSlot m_aSlots[NET_MAX_CONSOLE_CLIENTS]; NETFUNC_NEWCLIENT m_pfnNewClient; @@ -358,7 +309,7 @@ void SetCallbacks(NETFUNC_NEWCLIENT pfnNewClient, NETFUNC_DELCLIENT pfnDelClient, void *pUser); // - bool Open(NETADDR BindAddr, int Flags); + bool Open(NETADDR BindAddr, class CNetBan *pNetBan, int Flags); int Close(); // @@ -370,10 +321,9 @@ int AcceptClient(NETSOCKET Socket, const NETADDR *pAddr); int Drop(int ClientID, const char *pReason); - bool AddBan(NETADDR Addr, int Seconds); - // status requests - NETADDR ClientAddr(int ClientID) const { return m_aSlots[ClientID].m_Connection.PeerAddress(); } + const NETADDR *ClientAddr(int ClientID) const { return m_aSlots[ClientID].m_Connection.PeerAddress(); } + class CNetBan *NetBan() const { return m_pNetBan; } }; @@ -405,7 +355,7 @@ int ResetErrorString(); // error and state - int NetType() { return m_Socket.type; } + int NetType() const { return m_Socket.type; } int State(); int GotProblems(); const char *ErrorString(); diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/network_client.cpp teeworlds-0.6.2+dfsg/src/engine/shared/network_client.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/network_client.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/network_client.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -16,7 +16,7 @@ // init m_Socket = Socket; - m_Connection.Init(m_Socket); + m_Connection.Init(m_Socket, false); return true; } diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/network_conn.cpp teeworlds-0.6.2+dfsg/src/engine/shared/network_conn.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/network_conn.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/network_conn.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -37,12 +37,13 @@ str_copy(m_ErrorString, pString, sizeof(m_ErrorString)); } -void CNetConnection::Init(NETSOCKET Socket) +void CNetConnection::Init(NETSOCKET Socket, bool BlockCloseMsg) { Reset(); ResetStats(); m_Socket = Socket; + m_BlockCloseMsg = BlockCloseMsg; mem_zero(m_ErrorString, sizeof(m_ErrorString)); } @@ -213,24 +214,25 @@ m_State = NET_CONNSTATE_ERROR; m_RemoteClosed = 1; - if(pPacket->m_DataSize) + char Str[128] = {0}; + if(pPacket->m_DataSize > 1) { // make sure to sanitize the error string form the other party - char Str[128]; if(pPacket->m_DataSize < 128) - str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize); + str_copy(Str, (char *)&pPacket->m_aChunkData[1], pPacket->m_DataSize); else - str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str)); + str_copy(Str, (char *)&pPacket->m_aChunkData[1], sizeof(Str)); str_sanitize_strong(Str); + } + if(!m_BlockCloseMsg) + { // set the error string SetError(Str); } - else - SetError("No reason given"); if(g_Config.m_Debug) - dbg_msg("conn", "closed reason='%s'", ErrorString()); + dbg_msg("conn", "closed reason='%s'", Str); } return 0; } @@ -244,6 +246,7 @@ Reset(); m_State = NET_CONNSTATE_PENDING; m_PeerAddr = *pAddr; + mem_zero(m_ErrorString, sizeof(m_ErrorString)); m_LastSendTime = Now; m_LastRecvTime = Now; m_LastUpdateTime = Now; diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/network_console.cpp teeworlds-0.6.2+dfsg/src/engine/shared/network_console.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/network_console.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/network_console.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -1,15 +1,21 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include + +#include + +#include "netban.h" #include "network.h" -bool CNetConsole::Open(NETADDR BindAddr, int Flags) + +bool CNetConsole::Open(NETADDR BindAddr, CNetBan *pNetBan, int Flags) { // zero out the whole structure mem_zero(this, sizeof(*this)); m_Socket.type = NETTYPE_INVALID; m_Socket.ipv4sock = -1; m_Socket.ipv6sock = -1; + m_pNetBan = pNetBan; // open socket m_Socket = net_tcp_create(BindAddr); @@ -56,7 +62,7 @@ { char aError[256] = { 0 }; int FreeSlot = -1; - + // look for free slot or multiple client for(int i = 0; i < NET_MAX_CONSOLE_CLIENTS; i++) { @@ -64,8 +70,7 @@ FreeSlot = i; if(m_aSlots[i].m_Connection.State() != NET_CONNSTATE_OFFLINE) { - NETADDR PeerAddr = m_aSlots[i].m_Connection.PeerAddress(); - if(net_addr_comp(pAddr, &PeerAddr) == 0) + if(net_addr_comp(pAddr, m_aSlots[i].m_Connection.PeerAddress()) == 0) { str_copy(aError, "only one client per IP allowed", sizeof(aError)); break; @@ -99,26 +104,16 @@ if(net_tcp_accept(m_Socket, &Socket, &Addr) > 0) { - int Index = FindBan(Addr); - if(Index == -1) - AcceptClient(Socket, &Addr); - else + // check if we just should drop the packet + char aBuf[128]; + if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf))) { - char aBuf[128]; - if(m_aBans[Index].m_Expires > -1) - { - int Mins = (m_aBans[Index].m_Expires-time_timestamp()+ 59) / 60; - if(Mins <= 1) - str_format(aBuf, sizeof(aBuf), "You have been banned for 1 minute"); - else - str_format(aBuf, sizeof(aBuf), "You have been banned for %d minutes", Mins); - } - else - str_format(aBuf, sizeof(aBuf), "You have been banned for life"); - + // banned, reply with a message and drop net_tcp_send(Socket, aBuf, str_length(aBuf)); net_tcp_close(Socket); } + else + AcceptClient(Socket, &Addr); } for(int i = 0; i < NET_MAX_CONSOLE_CLIENTS; i++) @@ -129,8 +124,6 @@ Drop(i, m_aSlots[i].m_Connection.ErrorString()); } - UpdateBans(); - return 0; } @@ -155,65 +148,3 @@ else return -1; } - -int CNetConsole::FindBan(NETADDR Addr) -{ - Addr.port = 0; - for(int i = 0; i < m_NumBans; i++) - if(net_addr_comp(&m_aBans[i].m_Addr, &Addr) == 0) - return i; - - return -1; -} - -bool CNetConsole::AddBan(NETADDR Addr, int Seconds) -{ - if(m_NumBans == MAX_BANS) - return false; - - Addr.port = 0; - int Index = FindBan(Addr); - if(Index == -1) - { - Index = m_NumBans++; - m_aBans[Index].m_Addr = Addr; - } - m_aBans[Index].m_Expires = Seconds>0 ? time_timestamp()+Seconds : -1; - - for(int i = 0; i < NET_MAX_CONSOLE_CLIENTS; i++) - { - if(m_aSlots[i].m_Connection.State() != NET_CONNSTATE_OFFLINE) - { - NETADDR PeerAddr = m_aSlots[i].m_Connection.PeerAddress(); - PeerAddr.port = 0; - if(net_addr_comp(&Addr, &PeerAddr) == 0) - { - char aBuf[128]; - if(Seconds>0) - { - int Mins = (Seconds + 59) / 60; - if(Mins <= 1) - str_format(aBuf, sizeof(aBuf), "You have been banned for 1 minute"); - else - str_format(aBuf, sizeof(aBuf), "You have been banned for %d minutes", Mins); - } - else - str_format(aBuf, sizeof(aBuf), "You have been banned for life"); - Drop(i, aBuf); - } - } - } - return true; -} - -void CNetConsole::UpdateBans() -{ - int Now = time_timestamp(); - for(int i = 0; i < m_NumBans; ++i) - if(m_aBans[i].m_Expires > 0 && m_aBans[i].m_Expires < Now) - { - m_aBans[i] = m_aBans[m_NumBans-1]; - --m_NumBans; - break; - } -} diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/network_console_conn.cpp teeworlds-0.6.2+dfsg/src/engine/shared/network_console_conn.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/network_console_conn.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/network_console_conn.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -181,6 +181,6 @@ pData += Send; Length -= Send; } - + return 0; } diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/network_server.cpp teeworlds-0.6.2+dfsg/src/engine/shared/network_server.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/network_server.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/network_server.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -1,32 +1,14 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include "network.h" -#define MACRO_LIST_LINK_FIRST(Object, First, Prev, Next) \ - { if(First) First->Prev = Object; \ - Object->Prev = (struct CBan *)0; \ - Object->Next = First; \ - First = Object; } - -#define MACRO_LIST_LINK_AFTER(Object, After, Prev, Next) \ - { Object->Prev = After; \ - Object->Next = After->Next; \ - After->Next = Object; \ - if(Object->Next) \ - Object->Next->Prev = Object; \ - } +#include -#define MACRO_LIST_UNLINK(Object, First, Prev, Next) \ - { if(Object->Next) Object->Next->Prev = Object->Prev; \ - if(Object->Prev) Object->Prev->Next = Object->Next; \ - else First = Object->Next; \ - Object->Next = 0; Object->Prev = 0; } +#include "netban.h" +#include "network.h" -#define MACRO_LIST_FIND(Start, Next, Expression) \ - { while(Start && !(Expression)) Start = Start->Next; } -bool CNetServer::Open(NETADDR BindAddr, int MaxClients, int MaxClientsPerIP, int Flags) +bool CNetServer::Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int MaxClientsPerIP, int Flags) { // zero out the whole structure mem_zero(this, sizeof(*this)); @@ -36,6 +18,8 @@ if(!m_Socket.type) return false; + m_pNetBan = pNetBan; + // clamp clients m_MaxClients = MaxClients; if(m_MaxClients > NET_MAX_CLIENTS) @@ -46,18 +30,7 @@ m_MaxClientsPerIP = MaxClientsPerIP; for(int i = 0; i < NET_MAX_CLIENTS; i++) - m_aSlots[i].m_Connection.Init(m_Socket); - - // setup all pointers for bans - for(int i = 1; i < NET_SERVER_MAXBANS-1; i++) - { - m_BanPool[i].m_pNext = &m_BanPool[i+1]; - m_BanPool[i].m_pPrev = &m_BanPool[i-1]; - } - - m_BanPool[0].m_pNext = &m_BanPool[1]; - m_BanPool[NET_SERVER_MAXBANS-1].m_pPrev = &m_BanPool[NET_SERVER_MAXBANS-2]; - m_BanPool_FirstFree = &m_BanPool[0]; + m_aSlots[i].m_Connection.Init(m_Socket, true); return true; } @@ -94,171 +67,19 @@ return 0; } -int CNetServer::BanGet(int Index, CBanInfo *pInfo) -{ - CBan *pBan; - for(pBan = m_BanPool_FirstUsed; pBan && Index; pBan = pBan->m_pNext, Index--) - {} - - if(!pBan) - return 0; - *pInfo = pBan->m_Info; - return 1; -} - -int CNetServer::BanNum() -{ - int Count = 0; - CBan *pBan; - for(pBan = m_BanPool_FirstUsed; pBan; pBan = pBan->m_pNext) - Count++; - return Count; -} - -void CNetServer::BanRemoveByObject(CBan *pBan) -{ - int IpHash = (pBan->m_Info.m_Addr.ip[0]+pBan->m_Info.m_Addr.ip[1]+pBan->m_Info.m_Addr.ip[2]+pBan->m_Info.m_Addr.ip[3]+ - pBan->m_Info.m_Addr.ip[4]+pBan->m_Info.m_Addr.ip[5]+pBan->m_Info.m_Addr.ip[6]+pBan->m_Info.m_Addr.ip[7]+ - pBan->m_Info.m_Addr.ip[8]+pBan->m_Info.m_Addr.ip[9]+pBan->m_Info.m_Addr.ip[10]+pBan->m_Info.m_Addr.ip[11]+ - pBan->m_Info.m_Addr.ip[12]+pBan->m_Info.m_Addr.ip[13]+pBan->m_Info.m_Addr.ip[14]+pBan->m_Info.m_Addr.ip[15])&0xff; - char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&pBan->m_Info.m_Addr, aAddrStr, sizeof(aAddrStr)); - dbg_msg("netserver", "removing ban on %s", aAddrStr); - MACRO_LIST_UNLINK(pBan, m_BanPool_FirstUsed, m_pPrev, m_pNext); - MACRO_LIST_UNLINK(pBan, m_aBans[IpHash], m_pHashPrev, m_pHashNext); - MACRO_LIST_LINK_FIRST(pBan, m_BanPool_FirstFree, m_pPrev, m_pNext); -} - -int CNetServer::BanRemove(NETADDR Addr) -{ - int IpHash = (Addr.ip[0]+Addr.ip[1]+Addr.ip[2]+Addr.ip[3]+Addr.ip[4]+Addr.ip[5]+Addr.ip[6]+Addr.ip[7]+ - Addr.ip[8]+Addr.ip[9]+Addr.ip[10]+Addr.ip[11]+Addr.ip[12]+Addr.ip[13]+Addr.ip[14]+Addr.ip[15])&0xff; - CBan *pBan = m_aBans[IpHash]; - - MACRO_LIST_FIND(pBan, m_pHashNext, net_addr_comp(&pBan->m_Info.m_Addr, &Addr) == 0); - - if(pBan) - { - BanRemoveByObject(pBan); - return 0; - } - - return -1; -} - -int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason) -{ - int IpHash = (Addr.ip[0]+Addr.ip[1]+Addr.ip[2]+Addr.ip[3]+Addr.ip[4]+Addr.ip[5]+Addr.ip[6]+Addr.ip[7]+ - Addr.ip[8]+Addr.ip[9]+Addr.ip[10]+Addr.ip[11]+Addr.ip[12]+Addr.ip[13]+Addr.ip[14]+Addr.ip[15])&0xff; - int Stamp = -1; - CBan *pBan; - - // remove the port - Addr.port = 0; - - if(Seconds) - Stamp = time_timestamp() + Seconds; - - // search to see if it already exists - pBan = m_aBans[IpHash]; - MACRO_LIST_FIND(pBan, m_pHashNext, net_addr_comp(&pBan->m_Info.m_Addr, &Addr) == 0); - if(pBan) - { - // adjust the ban - pBan->m_Info.m_Expires = Stamp; - return 0; - } - - if(!m_BanPool_FirstFree) - return -1; - - // fetch and clear the new ban - pBan = m_BanPool_FirstFree; - MACRO_LIST_UNLINK(pBan, m_BanPool_FirstFree, m_pPrev, m_pNext); - - // setup the ban info - pBan->m_Info.m_Expires = Stamp; - pBan->m_Info.m_Addr = Addr; - str_copy(pBan->m_Info.m_Reason, pReason, sizeof(pBan->m_Info.m_Reason)); - - // add it to the ban hash - MACRO_LIST_LINK_FIRST(pBan, m_aBans[IpHash], m_pHashPrev, m_pHashNext); - - // insert it into the used list - { - if(m_BanPool_FirstUsed) - { - CBan *pInsertAfter = m_BanPool_FirstUsed; - MACRO_LIST_FIND(pInsertAfter, m_pNext, Stamp < pInsertAfter->m_Info.m_Expires); - - if(pInsertAfter) - pInsertAfter = pInsertAfter->m_pPrev; - else - { - // add to last - pInsertAfter = m_BanPool_FirstUsed; - while(pInsertAfter->m_pNext) - pInsertAfter = pInsertAfter->m_pNext; - } - - if(pInsertAfter) - { - MACRO_LIST_LINK_AFTER(pBan, pInsertAfter, m_pPrev, m_pNext); - } - else - { - MACRO_LIST_LINK_FIRST(pBan, m_BanPool_FirstUsed, m_pPrev, m_pNext); - } - } - else - { - MACRO_LIST_LINK_FIRST(pBan, m_BanPool_FirstUsed, m_pPrev, m_pNext); - } - } - - // drop banned clients - { - char Buf[128]; - NETADDR BanAddr; - - if(Stamp > -1) - { - int Mins = (Seconds + 59) / 60; - if(Mins <= 1) - str_format(Buf, sizeof(Buf), "You have been banned for 1 minute (%s)", pReason); - else - str_format(Buf, sizeof(Buf), "You have been banned for %d minutes (%s)", Mins, pReason); - } - else - str_format(Buf, sizeof(Buf), "You have been banned for life (%s)", pReason); - - for(int i = 0; i < MaxClients(); i++) - { - BanAddr = m_aSlots[i].m_Connection.PeerAddress(); - BanAddr.port = 0; - - if(net_addr_comp(&Addr, &BanAddr) == 0) - Drop(i, Buf); - } - } - return 0; -} - int CNetServer::Update() { - int Now = time_timestamp(); + int64 Now = time_get(); for(int i = 0; i < MaxClients(); i++) { m_aSlots[i].m_Connection.Update(); if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR) - Drop(i, m_aSlots[i].m_Connection.ErrorString()); - } - - // remove expired bans - while(m_BanPool_FirstUsed && m_BanPool_FirstUsed->m_Info.m_Expires > -1 && m_BanPool_FirstUsed->m_Info.m_Expires < Now) - { - CBan *pBan = m_BanPool_FirstUsed; - BanRemoveByObject(pBan); + { + if(Now - m_aSlots[i].m_Connection.ConnectTime() < time_freq() && NetBan()) + NetBan()->BanAddr(ClientAddr(i), 60, "Stressing network"); + else + Drop(i, m_aSlots[i].m_Connection.ErrorString()); + } } return 0; @@ -269,8 +90,6 @@ */ int CNetServer::Recv(CNetChunk *pChunk) { - unsigned Now = time_timestamp(); - while(1) { NETADDR Addr; @@ -288,36 +107,12 @@ if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data) == 0) { - CBan *pBan = 0; - NETADDR BanAddr = Addr; - int IpHash = (BanAddr.ip[0]+BanAddr.ip[1]+BanAddr.ip[2]+BanAddr.ip[3]+BanAddr.ip[4]+BanAddr.ip[5]+BanAddr.ip[6]+BanAddr.ip[7]+ - BanAddr.ip[8]+BanAddr.ip[9]+BanAddr.ip[10]+BanAddr.ip[11]+BanAddr.ip[12]+BanAddr.ip[13]+BanAddr.ip[14]+BanAddr.ip[15])&0xff; - int Found = 0; - BanAddr.port = 0; - - // search a ban - for(pBan = m_aBans[IpHash]; pBan; pBan = pBan->m_pHashNext) - { - if(net_addr_comp(&pBan->m_Info.m_Addr, &BanAddr) == 0) - break; - } - // check if we just should drop the packet - if(pBan) + char aBuf[128]; + if(NetBan() && NetBan()->IsBanned(&Addr, aBuf, sizeof(aBuf))) { // banned, reply with a message - char BanStr[128]; - if(pBan->m_Info.m_Expires > -1) - { - int Mins = ((pBan->m_Info.m_Expires - Now)+59)/60; - if(Mins <= 1) - str_format(BanStr, sizeof(BanStr), "Banned for 1 minute (%s)", pBan->m_Info.m_Reason); - else - str_format(BanStr, sizeof(BanStr), "Banned for %d minutes (%s)", Mins, pBan->m_Info.m_Reason); - } - else - str_format(BanStr, sizeof(BanStr), "Banned for life (%s)", pBan->m_Info.m_Reason); - CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, BanStr, str_length(BanStr)+1); + CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, aBuf, str_length(aBuf)+1); continue; } @@ -335,16 +130,15 @@ // TODO: check size here if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL && m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_CONNECT) { - Found = 0; + bool Found = false; // check if we already got this client for(int i = 0; i < MaxClients(); i++) { - NETADDR PeerAddr = m_aSlots[i].m_Connection.PeerAddress(); if(m_aSlots[i].m_Connection.State() != NET_CONNSTATE_OFFLINE && - net_addr_comp(&PeerAddr, &Addr) == 0) + net_addr_comp(m_aSlots[i].m_Connection.PeerAddress(), &Addr) == 0) { - Found = 1; // silent ignore.. we got this client already + Found = true; // silent ignore.. we got this client already break; } } @@ -361,7 +155,7 @@ if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_OFFLINE) continue; - OtherAddr = m_aSlots[i].m_Connection.PeerAddress(); + OtherAddr = *m_aSlots[i].m_Connection.PeerAddress(); OtherAddr.port = 0; if(!net_addr_comp(&ThisAddr, &OtherAddr)) { @@ -379,7 +173,7 @@ { if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_OFFLINE) { - Found = 1; + Found = true; m_aSlots[i].m_Connection.Feed(&m_RecvUnpacker.m_Data, &Addr); if(m_pfnNewClient) m_pfnNewClient(i, m_UserPtr); @@ -399,8 +193,7 @@ // normal packet, find matching slot for(int i = 0; i < MaxClients(); i++) { - NETADDR PeerAddr = m_aSlots[i].m_Connection.PeerAddress(); - if(net_addr_comp(&PeerAddr, &Addr) == 0) + if(net_addr_comp(m_aSlots[i].m_Connection.PeerAddress(), &Addr) == 0) { if(m_aSlots[i].m_Connection.Feed(&m_RecvUnpacker.m_Data, &Addr)) { diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/packer.cpp teeworlds-0.6.2+dfsg/src/engine/shared/packer.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/packer.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/packer.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -136,7 +136,7 @@ str_sanitize(pPtr); else if(SanitizeType&SANITIZE_CC) str_sanitize_cc(pPtr); - return SanitizeType&SKIP_START_WHITESPACES ? str_skip_whitespaces(pPtr) : pPtr; + return SanitizeType&SKIP_START_WHITESPACES ? str_utf8_skip_whitespaces(pPtr) : pPtr; } const unsigned char *CUnpacker::GetRaw(int Size) diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/snapshot.cpp teeworlds-0.6.2+dfsg/src/engine/shared/snapshot.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/snapshot.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/snapshot.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -195,13 +195,14 @@ // fetch previous indices // we do this as a separate pass because it helps the cache - for(i = 0; i < pTo->NumItems(); i++) + const int NumItems = pTo->NumItems(); + for(i = 0; i < NumItems; i++) { pCurItem = pTo->GetItem(i); // O(1) .. O(n) aPastIndecies[i] = GetItemIndexHashed(pCurItem->Key(), Hashlist); // O(n) .. O(n^n) } - for(i = 0; i < pTo->NumItems(); i++) + for(i = 0; i < NumItems; i++) { // do delta ItemSize = pTo->GetItemSize(i); // O(1) .. O(n) @@ -474,7 +475,7 @@ if(ppData) *ppData = pHolder->m_pSnap; if(ppAltData) - *ppData = pHolder->m_pAltSnap; + *ppAltData = pHolder->m_pAltSnap; return pHolder->m_SnapSize; } diff -Nru teeworlds-0.6.1+dfsg/src/engine/shared/storage.cpp teeworlds-0.6.2+dfsg/src/engine/shared/storage.cpp --- teeworlds-0.6.1+dfsg/src/engine/shared/storage.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/shared/storage.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -30,7 +30,7 @@ m_aUserdir[0] = 0; } - int Init(const char *pApplicationName, int NumArgs, const char **ppArguments) + int Init(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments) { // get userdir fs_storage_path(pApplicationName, m_aUserdir, sizeof(m_aUserdir)); @@ -52,14 +52,17 @@ } // add save directories - if(m_NumPaths && (!m_aaStoragePaths[TYPE_SAVE][0] || !fs_makedir(m_aaStoragePaths[TYPE_SAVE]))) + if(StorageType != STORAGETYPE_BASIC && m_NumPaths && (!m_aaStoragePaths[TYPE_SAVE][0] || !fs_makedir(m_aaStoragePaths[TYPE_SAVE]))) { char aPath[MAX_PATH_LENGTH]; - fs_makedir(GetPath(TYPE_SAVE, "screenshots", aPath, sizeof(aPath))); - fs_makedir(GetPath(TYPE_SAVE, "screenshots/auto", aPath, sizeof(aPath))); - fs_makedir(GetPath(TYPE_SAVE, "maps", aPath, sizeof(aPath))); + if(StorageType == STORAGETYPE_CLIENT) + { + fs_makedir(GetPath(TYPE_SAVE, "screenshots", aPath, sizeof(aPath))); + fs_makedir(GetPath(TYPE_SAVE, "screenshots/auto", aPath, sizeof(aPath))); + fs_makedir(GetPath(TYPE_SAVE, "maps", aPath, sizeof(aPath))); + fs_makedir(GetPath(TYPE_SAVE, "downloadedmaps", aPath, sizeof(aPath))); + } fs_makedir(GetPath(TYPE_SAVE, "dumps", aPath, sizeof(aPath))); - fs_makedir(GetPath(TYPE_SAVE, "downloadedmaps", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "demos", aPath, sizeof(aPath))); fs_makedir(GetPath(TYPE_SAVE, "demos/auto", aPath, sizeof(aPath))); } @@ -377,10 +380,22 @@ return !fs_makedir(GetPath(Type, pFoldername, aBuffer, sizeof(aBuffer))); } - static IStorage *Create(const char *pApplicationName, int NumArgs, const char **ppArguments) + virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize) + { + if(Type < 0 || Type >= m_NumPaths) + { + if(BufferSize > 0) + pBuffer[0] = 0; + return; + } + + GetPath(Type, pDir, pBuffer, BufferSize); + } + + static IStorage *Create(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments) { CStorage *p = new CStorage(); - if(p && p->Init(pApplicationName, NumArgs, ppArguments)) + if(p && p->Init(pApplicationName, StorageType, NumArgs, ppArguments)) { dbg_msg("storage", "initialisation failed"); delete p; @@ -390,4 +405,4 @@ } }; -IStorage *CreateStorage(const char *pApplicationName, int NumArgs, const char **ppArguments) { return CStorage::Create(pApplicationName, NumArgs, ppArguments); } +IStorage *CreateStorage(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments) { return CStorage::Create(pApplicationName, StorageType, NumArgs, ppArguments); } diff -Nru teeworlds-0.6.1+dfsg/src/engine/sound.h teeworlds-0.6.2+dfsg/src/engine/sound.h --- teeworlds-0.6.1+dfsg/src/engine/sound.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/sound.h 2013-05-01 11:47:39.000000000 +0000 @@ -19,10 +19,10 @@ virtual bool IsSoundEnabled() = 0; virtual int LoadWV(const char *pFilename) = 0; - + virtual void SetChannel(int ChannelID, float Volume, float Panning) = 0; virtual void SetListenerPos(float x, float y) = 0; - + virtual int PlayAt(int ChannelID, int SampleID, int Flags, float x, float y) = 0; virtual int Play(int ChannelID, int SampleID, int Flags) = 0; virtual void Stop(int SampleID) = 0; diff -Nru teeworlds-0.6.1+dfsg/src/engine/storage.h teeworlds-0.6.2+dfsg/src/engine/storage.h --- teeworlds-0.6.1+dfsg/src/engine/storage.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/engine/storage.h 2013-05-01 11:47:39.000000000 +0000 @@ -12,7 +12,11 @@ enum { TYPE_SAVE = 0, - TYPE_ALL = -1 + TYPE_ALL = -1, + + STORAGETYPE_BASIC = 0, + STORAGETYPE_SERVER, + STORAGETYPE_CLIENT, }; virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0; @@ -21,9 +25,10 @@ virtual bool RemoveFile(const char *pFilename, int Type) = 0; virtual bool RenameFile(const char* pOldFilename, const char* pNewFilename, int Type) = 0; virtual bool CreateFolder(const char *pFoldername, int Type) = 0; + virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize) = 0; }; -extern IStorage *CreateStorage(const char *pApplicationName, int NumArgs, const char **ppArguments); +extern IStorage *CreateStorage(const char *pApplicationName, int StorageType, int NumArgs, const char **ppArguments); #endif diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/chat.cpp teeworlds-0.6.2+dfsg/src/game/client/components/chat.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/chat.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/chat.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -41,6 +41,11 @@ m_PlaceholderOffset = 0; m_PlaceholderLength = 0; m_pHistoryEntry = 0x0; + m_PendingChatCounter = 0; + m_LastChatSend = 0; + + for(int i = 0; i < CHAT_NUM; ++i) + m_aLastSoundPlayed[i] = 0; } void CChat::OnRelease() @@ -107,9 +112,25 @@ { if(m_Input.GetString()[0]) { - Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString()); - char *pEntry = m_History.Allocate(m_Input.GetLength()+1); - mem_copy(pEntry, m_Input.GetString(), m_Input.GetLength()+1); + bool AddEntry = false; + + if(m_LastChatSend+time_freq() < time_get()) + { + Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString()); + AddEntry = true; + } + else if(m_PendingChatCounter < 3) + { + ++m_PendingChatCounter; + AddEntry = true; + } + + if(AddEntry) + { + CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry)+m_Input.GetLength()); + pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1; + mem_copy(pEntry->m_aText, m_Input.GetString(), m_Input.GetLength()+1); + } } m_pHistoryEntry = 0x0; m_Mode = MODE_NONE; @@ -199,26 +220,26 @@ } if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_UP) { - if (m_pHistoryEntry) + if(m_pHistoryEntry) { - char *pTest = m_History.Prev(m_pHistoryEntry); + CHistoryEntry *pTest = m_History.Prev(m_pHistoryEntry); - if (pTest) + if(pTest) m_pHistoryEntry = pTest; } else m_pHistoryEntry = m_History.Last(); - if (m_pHistoryEntry) - m_Input.Set(m_pHistoryEntry); + if(m_pHistoryEntry) + m_Input.Set(m_pHistoryEntry->m_aText); } else if (Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_DOWN) { - if (m_pHistoryEntry) + if(m_pHistoryEntry) m_pHistoryEntry = m_History.Next(m_pHistoryEntry); if (m_pHistoryEntry) - m_Input.Set(m_pHistoryEntry); + m_Input.Set(m_pHistoryEntry->m_aText); else m_Input.Clear(); } @@ -256,10 +277,39 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine) { - if(ClientID != -1 && (m_pClient->m_aClients[ClientID].m_aName[0] == '\0' || // unknown client - m_pClient->m_aClients[ClientID].m_ChatIgnore)) + if(*pLine == 0 || (ClientID != -1 && (m_pClient->m_aClients[ClientID].m_aName[0] == '\0' || // unknown client + m_pClient->m_aClients[ClientID].m_ChatIgnore || + (m_pClient->m_Snap.m_LocalClientID != ClientID && g_Config.m_ClShowChatFriends && !m_pClient->m_aClients[ClientID].m_Friend)))) return; + // trim right and set maximum length to 128 utf8-characters + int Length = 0; + const char *pStr = pLine; + const char *pEnd = 0; + while(*pStr) + { + const char *pStrOld = pStr; + int Code = str_utf8_decode(&pStr); + + // check if unicode is not empty + if(Code > 0x20 && Code != 0xA0 && Code != 0x034F && (Code < 0x2000 || Code > 0x200F) && (Code < 0x2028 || Code > 0x202F) && + (Code < 0x205F || Code > 0x2064) && (Code < 0x206A || Code > 0x206F) && (Code < 0xFE00 || Code > 0xFE0F) && + Code != 0xFEFF && (Code < 0xFFF9 || Code > 0xFFFC)) + { + pEnd = 0; + } + else if(pEnd == 0) + pEnd = pStrOld; + + if(++Length >= 127) + { + *(const_cast(pStr)) = 0; + break; + } + } + if(pEnd != 0) + *(const_cast(pEnd)) = 0; + bool Highlighted = false; char *p = const_cast(pLine); while(*p) @@ -283,7 +333,7 @@ m_aLines[m_CurrentLine].m_ClientID = ClientID; m_aLines[m_CurrentLine].m_Team = Team; m_aLines[m_CurrentLine].m_NameColor = -2; - + // check for highlighted name const char *pHL = str_find_nocase(pLine, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName); if(pHL) @@ -322,16 +372,50 @@ } // play sound + int64 Now = time_get(); if(ClientID == -1) - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_SERVER, 0, vec2(0,0)); + { + if(Now-m_aLastSoundPlayed[CHAT_SERVER] >= time_freq()*3/10) + { + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_SERVER, 0); + m_aLastSoundPlayed[CHAT_SERVER] = Now; + } + } else if(Highlighted) - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0, vec2(0.0f, 0.0f)); + { + if(Now-m_aLastSoundPlayed[CHAT_HIGHLIGHT] >= time_freq()*3/10) + { + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0); + m_aLastSoundPlayed[CHAT_HIGHLIGHT] = Now; + } + } else - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0, vec2(0,0)); + { + if(Now-m_aLastSoundPlayed[CHAT_CLIENT] >= time_freq()*3/10) + { + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0); + m_aLastSoundPlayed[CHAT_CLIENT] = Now; + } + } } void CChat::OnRender() { + // send pending chat messages + if(m_PendingChatCounter > 0 && m_LastChatSend+time_freq() < time_get()) + { + CHistoryEntry *pEntry = m_History.Last(); + for(int i = m_PendingChatCounter-1; pEntry; --i, pEntry = m_History.Prev(pEntry)) + { + if(i == 0) + { + Say(pEntry->m_Team, pEntry->m_aText); + break; + } + } + --m_PendingChatCounter; + } + float Width = 300.0f*Graphics()->ScreenAspect(); Graphics()->MapScreen(0.0f, 0.0f, Width, 300.0f); float x = 5.0f; @@ -457,6 +541,8 @@ void CChat::Say(int Team, const char *pLine) { + m_LastChatSend = time_get(); + // send chat message CNetMsg_Cl_Say Msg; Msg.m_Team = Team; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/chat.h teeworlds-0.6.2+dfsg/src/game/client/components/chat.h --- teeworlds-0.6.1+dfsg/src/game/client/components/chat.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/chat.h 2013-05-01 11:47:39.000000000 +0000 @@ -36,6 +36,11 @@ MODE_NONE=0, MODE_ALL, MODE_TEAM, + + CHAT_SERVER=0, + CHAT_HIGHLIGHT, + CHAT_CLIENT, + CHAT_NUM, }; int m_Mode; @@ -47,8 +52,17 @@ char m_aCompletionBuffer[256]; int m_PlaceholderOffset; int m_PlaceholderLength; - char *m_pHistoryEntry; - TStaticRingBuffer m_History; + + struct CHistoryEntry + { + int m_Team; + char m_aText[1]; + }; + CHistoryEntry *m_pHistoryEntry; + TStaticRingBuffer m_History; + int m_PendingChatCounter; + int64 m_LastChatSend; + int64 m_aLastSoundPlayed[CHAT_NUM]; static void ConSay(IConsole::IResult *pResult, void *pUserData); static void ConSayTeam(IConsole::IResult *pResult, void *pUserData); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/console.cpp teeworlds-0.6.2+dfsg/src/game/client/components/console.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/console.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/console.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -434,12 +434,6 @@ x = Cursor.m_X; - // render console input (wrap line) - int Lines = TextRender()->TextLineCount(0, FontSize, pConsole->m_Input.GetString(), Screen.w - 10.0f - x); - y -= (Lines - 1) * FontSize; - TextRender()->SetCursor(&Cursor, x, y, FontSize, TEXTFLAG_RENDER); - Cursor.m_LineWidth = Screen.w - 10.0f - x; - //hide rcon password char aInputString[256]; str_copy(aInputString, pConsole->m_Input.GetString(), sizeof(aInputString)); @@ -449,10 +443,22 @@ aInputString[i] = '*'; } + // render console input (wrap line) + TextRender()->SetCursor(&Cursor, x, y, FontSize, 0); + Cursor.m_LineWidth = Screen.w - 10.0f - x; + TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset()); + TextRender()->TextEx(&Cursor, aInputString+pConsole->m_Input.GetCursorOffset(), -1); + int Lines = Cursor.m_LineCount; + + y -= (Lines - 1) * FontSize; + TextRender()->SetCursor(&Cursor, x, y, FontSize, TEXTFLAG_RENDER); + Cursor.m_LineWidth = Screen.w - 10.0f - x; + TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset()); static float MarkerOffset = TextRender()->TextWidth(0, FontSize, "|", -1)/3; CTextCursor Marker = Cursor; Marker.m_X -= MarkerOffset; + Marker.m_LineWidth = -1; TextRender()->TextEx(&Marker, "|", -1); TextRender()->TextEx(&Cursor, aInputString+pConsole->m_Input.GetCursorOffset(), -1); @@ -612,16 +618,10 @@ IOHANDLE io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); if(io) { - #if defined(CONF_FAMILY_WINDOWS) - static const char Newline[] = "\r\n"; - #else - static const char Newline[] = "\n"; - #endif - for(CInstance::CBacklogEntry *pEntry = pConsole->m_Backlog.First(); pEntry; pEntry = pConsole->m_Backlog.Next(pEntry)) { io_write(io, pEntry->m_aText, str_length(pEntry->m_aText)); - io_write(io, Newline, sizeof(Newline)-1); + io_write_newline(io); } io_close(io); } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/controls.cpp teeworlds-0.6.2+dfsg/src/game/client/components/controls.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/controls.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/controls.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -199,7 +199,7 @@ void CControls::OnRender() { // update target pos - if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED || m_pClient->m_Snap.m_SpecInfo.m_Active)) + if(m_pClient->m_Snap.m_pGameInfoObj && !m_pClient->m_Snap.m_SpecInfo.m_Active) m_TargetPos = m_pClient->m_LocalCharacterPos + m_MousePos; else if(m_pClient->m_Snap.m_SpecInfo.m_Active && m_pClient->m_Snap.m_SpecInfo.m_UsePosition) m_TargetPos = m_pClient->m_Snap.m_SpecInfo.m_Position + m_MousePos; @@ -209,7 +209,8 @@ bool CControls::OnMouseMove(float x, float y) { - if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) + if((m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) || + (m_pClient->m_Snap.m_SpecInfo.m_Active && m_pClient->m_pChat->IsActive())) return false; m_MousePos += vec2(x, y); // TODO: ugly diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/countryflags.cpp teeworlds-0.6.2+dfsg/src/game/client/components/countryflags.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/countryflags.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/countryflags.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include "countryflags.h" @@ -56,31 +58,57 @@ // load the graphic file char aBuf[128]; - str_format(aBuf, sizeof(aBuf), "countryflags/%s.png", aOrigin); CImageInfo Info; - if(!Graphics()->LoadPNG(&Info, aBuf, IStorage::TYPE_ALL)) + if(g_Config.m_ClLoadCountryFlags) { - char aMsg[128]; - str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf); - Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aMsg); - continue; + str_format(aBuf, sizeof(aBuf), "countryflags/%s.png", aOrigin); + if(!Graphics()->LoadPNG(&Info, aBuf, IStorage::TYPE_ALL)) + { + char aMsg[128]; + str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aMsg); + continue; + } } // add entry CCountryFlag CountryFlag; CountryFlag.m_CountryCode = CountryCode; str_copy(CountryFlag.m_aCountryCodeString, aOrigin, sizeof(CountryFlag.m_aCountryCodeString)); - CountryFlag.m_Texture = Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); - mem_free(Info.m_pData); - str_format(aBuf, sizeof(aBuf), "loaded country flag '%s'", aOrigin); - Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aBuf); - m_aCountryFlags.add(CountryFlag); + if(g_Config.m_ClLoadCountryFlags) + { + CountryFlag.m_Texture = Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); + mem_free(Info.m_pData); + } + else + CountryFlag.m_Texture = -1; + if(g_Config.m_Debug) + { + str_format(aBuf, sizeof(aBuf), "loaded country flag '%s'", aOrigin); + Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aBuf); + } + m_aCountryFlags.add_unsorted(CountryFlag); } io_close(File); + m_aCountryFlags.sort_range(); - mem_zero(m_CodeIndexLUT, sizeof(m_CodeIndexLUT)); + // find index of default item + int DefaultIndex = 0, Index = 0; + for(sorted_array::range r = m_aCountryFlags.all(); !r.empty(); r.pop_front(), ++Index) + if(r.front().m_CountryCode == -1) + { + DefaultIndex = Index; + break; + } + + // init LUT + if(DefaultIndex != 0) + for(int i = 0; i < CODE_RANGE; ++i) + m_CodeIndexLUT[i] = DefaultIndex; + else + mem_zero(m_CodeIndexLUT, sizeof(m_CodeIndexLUT)); for(int i = 0; i < m_aCountryFlags.size(); ++i) - m_CodeIndexLUT[max(0, (m_aCountryFlags[i].m_CountryCode-CODE_LB)%CODE_RANGE)] = i+1; + m_CodeIndexLUT[max(0, (m_aCountryFlags[i].m_CountryCode-CODE_LB)%CODE_RANGE)] = i; } void CCountryFlags::OnInit() @@ -94,6 +122,7 @@ CCountryFlag DummyEntry; DummyEntry.m_CountryCode = -1; DummyEntry.m_Texture = -1; + mem_zero(DummyEntry.m_aCountryCodeString, sizeof(DummyEntry.m_aCountryCodeString)); m_aCountryFlags.add(DummyEntry); } } @@ -105,10 +134,31 @@ const CCountryFlags::CCountryFlag *CCountryFlags::GetByCountryCode(int CountryCode) const { - return GetByIndex(m_CodeIndexLUT[max(0, (CountryCode-CODE_LB)%CODE_RANGE)]-1); + return GetByIndex(m_CodeIndexLUT[max(0, (CountryCode-CODE_LB)%CODE_RANGE)]); } const CCountryFlags::CCountryFlag *CCountryFlags::GetByIndex(int Index) const { return &m_aCountryFlags[max(0, Index%m_aCountryFlags.size())]; } + +void CCountryFlags::Render(int CountryCode, const vec4 *pColor, float x, float y, float w, float h) +{ + const CCountryFlag *pFlag = GetByCountryCode(CountryCode); + if(pFlag->m_Texture != -1) + { + Graphics()->TextureSet(pFlag->m_Texture); + Graphics()->QuadsBegin(); + Graphics()->SetColor(pColor->r, pColor->g, pColor->b, pColor->a); + IGraphics::CQuadItem QuadItem(x, y, w, h); + Graphics()->QuadsDrawTL(&QuadItem, 1); + Graphics()->QuadsEnd(); + } + else + { + CTextCursor Cursor; + TextRender()->SetCursor(&Cursor, x, y, 10.0f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); + Cursor.m_LineWidth = w; + TextRender()->TextEx(&Cursor, pFlag->m_aCountryCodeString, -1); + } +} diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/countryflags.h teeworlds-0.6.2+dfsg/src/game/client/components/countryflags.h --- teeworlds-0.6.1+dfsg/src/game/client/components/countryflags.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/countryflags.h 2013-05-01 11:47:39.000000000 +0000 @@ -23,7 +23,7 @@ int Num() const; const CCountryFlag *GetByCountryCode(int CountryCode) const; const CCountryFlag *GetByIndex(int Index) const; - //int Find(int CountryCode) const; + void Render(int CountryCode, const vec4 *pColor, float x, float y, float w, float h); private: enum diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/damageind.cpp teeworlds-0.6.2+dfsg/src/game/client/components/damageind.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/damageind.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/damageind.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -1,5 +1,6 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include #include #include #include @@ -38,7 +39,7 @@ if (i) { i->m_Pos = Pos; - i->m_Life = 0.75f; + i->m_StartTime = Client()->LocalTime(); i->m_Dir = Dir*-1; i->m_StartAngle = (( (float)rand()/(float)RAND_MAX) - 1.0f) * 2.0f * pi; } @@ -48,21 +49,39 @@ { Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id); Graphics()->QuadsBegin(); + static float s_LastLocalTime = Client()->LocalTime(); for(int i = 0; i < m_NumItems;) { - vec2 Pos = mix(m_aItems[i].m_Pos+m_aItems[i].m_Dir*75.0f, m_aItems[i].m_Pos, clamp((m_aItems[i].m_Life-0.60f)/0.15f, 0.0f, 1.0f)); + if(Client()->State() == IClient::STATE_DEMOPLAYBACK) + { + const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); + if(pInfo->m_Paused) + m_aItems[i].m_StartTime += Client()->LocalTime()-s_LastLocalTime; + else + m_aItems[i].m_StartTime += (Client()->LocalTime()-s_LastLocalTime)*(1.0f-pInfo->m_Speed); + } + else + { + if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) + m_aItems[i].m_StartTime += Client()->LocalTime()-s_LastLocalTime; + } - m_aItems[i].m_Life -= Client()->FrameTime(); - if(m_aItems[i].m_Life < 0.0f) + float Life = 0.75f - (Client()->LocalTime() - m_aItems[i].m_StartTime); + if(Life < 0.0f) DestroyI(&m_aItems[i]); else { - Graphics()->SetColor(1.0f,1.0f,1.0f, m_aItems[i].m_Life/0.1f); - Graphics()->QuadsSetRotation(m_aItems[i].m_StartAngle + m_aItems[i].m_Life * 2.0f); + vec2 Pos = mix(m_aItems[i].m_Pos+m_aItems[i].m_Dir*75.0f, m_aItems[i].m_Pos, clamp((Life-0.60f)/0.15f, 0.0f, 1.0f)); + Graphics()->SetColor(1.0f,1.0f,1.0f, Life/0.1f); + Graphics()->QuadsSetRotation(m_aItems[i].m_StartAngle + Life * 2.0f); RenderTools()->SelectSprite(SPRITE_STAR1); RenderTools()->DrawSprite(Pos.x, Pos.y, 48.0f); i++; } } + s_LastLocalTime = Client()->LocalTime(); Graphics()->QuadsEnd(); } + + + diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/damageind.h teeworlds-0.6.2+dfsg/src/game/client/components/damageind.h --- teeworlds-0.6.1+dfsg/src/game/client/components/damageind.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/damageind.h 2013-05-01 11:47:39.000000000 +0000 @@ -12,7 +12,7 @@ { vec2 m_Pos; vec2 m_Dir; - float m_Life; + float m_StartTime; float m_StartAngle; }; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/effects.cpp teeworlds-0.6.2+dfsg/src/game/client/components/effects.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/effects.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/effects.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -44,7 +44,7 @@ p.m_Pos = Pos + vec2(6.0f, 16.0f); m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, Pos); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, Pos); } void CEffects::DamageIndicator(vec2 Pos, vec2 Dir) @@ -147,7 +147,7 @@ m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); } - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_PLAYER_SPAWN, 1.0f, Pos); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_SPAWN, 1.0f, Pos); } void CEffects::PlayerDeath(vec2 Pos, int ClientID) @@ -242,7 +242,7 @@ p.m_EndSize = 0; p.m_Rot = frandom()*pi*2; m_pClient->m_pParticles->Add(CParticles::GROUP_EXPLOSIONS, &p); - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_HAMMER_HIT, 1.0f, Pos); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_HAMMER_HIT, 1.0f, Pos); } void CEffects::OnRender() diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/emoticon.cpp teeworlds-0.6.2+dfsg/src/game/client/components/emoticon.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/emoticon.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/emoticon.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -111,14 +111,14 @@ m_WasActive = true; - if (length(m_SelectorMouse) > 140) - m_SelectorMouse = normalize(m_SelectorMouse) * 140; + if (length(m_SelectorMouse) > 170.0f) + m_SelectorMouse = normalize(m_SelectorMouse) * 170.0f; float SelectedAngle = GetAngle(m_SelectorMouse) + 2*pi/24; if (SelectedAngle < 0) SelectedAngle += 2*pi; - if (length(m_SelectorMouse) > 100) + if (length(m_SelectorMouse) > 110.0f) m_SelectedEmote = (int)(SelectedAngle / (2*pi) * NUM_EMOTICONS); CUIRect Screen = *UI()->Screen(); @@ -130,7 +130,7 @@ Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); Graphics()->SetColor(0,0,0,0.3f); - DrawCircle(Screen.w/2, Screen.h/2, 160, 64); + DrawCircle(Screen.w/2, Screen.h/2, 190.0f, 64); Graphics()->QuadsEnd(); Graphics()->TextureSet(g_pData->m_aImages[IMAGE_EMOTICONS].m_Id); @@ -144,10 +144,10 @@ bool Selected = m_SelectedEmote == i; - float Size = Selected ? 80 : 32; + float Size = Selected ? 80.0f : 50.0f; - float NudgeX = 120 * cosf(Angle); - float NudgeY = 120 * sinf(Angle); + float NudgeX = 150.0f * cosf(Angle); + float NudgeY = 150.0f * sinf(Angle); RenderTools()->SelectSprite(SPRITE_OOP + i); IGraphics::CQuadItem QuadItem(Screen.w/2 + NudgeX, Screen.h/2 + NudgeY, Size, Size); Graphics()->QuadsDraw(&QuadItem, 1); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/hud.cpp teeworlds-0.6.2+dfsg/src/game/client/components/hud.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/hud.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/hud.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -59,6 +59,18 @@ } } +void CHud::RenderPauseNotification() +{ + if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED && + !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER)) + { + const char *pText = Localize("Game paused"); + float FontSize = 20.0f; + float w = TextRender()->TextWidth(0, FontSize,pText, -1); + TextRender()->Text(0, 150.0f*Graphics()->ScreenAspect()+-w/2.0f, 50.0f, FontSize, pText, -1); + } +} + void CHud::RenderSuddenDeath() { if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_SUDDENDEATH) @@ -78,6 +90,7 @@ { int GameFlags = m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags; float Whole = 300*Graphics()->ScreenAspect(); + float StartY = 229.0f; if(GameFlags&GAMEFLAG_TEAMS && m_pClient->m_Snap.m_pGameDataObj) { @@ -100,15 +113,15 @@ Graphics()->SetColor(1.0f, 0.0f, 0.0f, 0.25f); else Graphics()->SetColor(0.0f, 0.0f, 1.0f, 0.25f); - RenderTools()->DrawRoundRectExt(Whole-ScoreWidthMax-ImageSize-2*Split, 245.0f+t*20, ScoreWidthMax+ImageSize+2*Split, 18.0f, 5.0f, CUI::CORNER_L); + RenderTools()->DrawRoundRectExt(Whole-ScoreWidthMax-ImageSize-2*Split, StartY+t*20, ScoreWidthMax+ImageSize+2*Split, 18.0f, 5.0f, CUI::CORNER_L); Graphics()->QuadsEnd(); // draw score - TextRender()->Text(0, Whole-ScoreWidthMax+(ScoreWidthMax-aScoreTeamWidth[t])/2-Split, 245.0f+t*20, 14.0f, aScoreTeam[t], -1); + TextRender()->Text(0, Whole-ScoreWidthMax+(ScoreWidthMax-aScoreTeamWidth[t])/2-Split, StartY+t*20, 14.0f, aScoreTeam[t], -1); if(GameFlags&GAMEFLAG_FLAGS) { - int BlinkTimer = (m_pClient->m_FlagDropTick[t] != 0 && + int BlinkTimer = (m_pClient->m_FlagDropTick[t] != 0 && (Client()->GameTick()-m_pClient->m_FlagDropTick[t])/Client()->GameTickSpeed() >= 25) ? 10 : 20; if(FlagCarrier[t] == FLAG_ATSTAND || (FlagCarrier[t] == FLAG_TAKEN && ((Client()->GameTick()/BlinkTimer)&1))) { @@ -117,7 +130,7 @@ Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id); Graphics()->QuadsBegin(); RenderTools()->SelectSprite(t==0?SPRITE_FLAG_RED:SPRITE_FLAG_BLUE); - IGraphics::CQuadItem QuadItem(Whole-ScoreWidthMax-ImageSize, 246.0f+t*20, ImageSize/2, ImageSize); + IGraphics::CQuadItem QuadItem(Whole-ScoreWidthMax-ImageSize, StartY+1.0f+t*20, ImageSize/2, ImageSize); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); } @@ -126,16 +139,17 @@ // draw name of the flag holder int ID = FlagCarrier[t]%MAX_CLIENTS; const char *pName = m_pClient->m_aClients[ID].m_aName; - float w = TextRender()->TextWidth(0, 10.0f, pName, -1); - TextRender()->Text(0, Whole-ScoreWidthMax-ImageSize-3*Split-w, 247.0f+t*20, 10.0f, pName, -1); + float w = TextRender()->TextWidth(0, 8.0f, pName, -1); + TextRender()->Text(0, min(Whole-w-1.0f, Whole-ScoreWidthMax-ImageSize-2*Split), StartY+(t+1)*20.0f-3.0f, 8.0f, pName, -1); // draw tee of the flag holder CTeeRenderInfo Info = m_pClient->m_aClients[ID].m_RenderInfo; Info.m_Size = 18.0f; RenderTools()->RenderTee(CAnimState::GetIdle(), &Info, EMOTE_NORMAL, vec2(1,0), - vec2(Whole-ScoreWidthMax-Info.m_Size/2-Split, 246.0f+Info.m_Size/2+t*20)); + vec2(Whole-ScoreWidthMax-Info.m_Size/2-Split, StartY+1.0f+Info.m_Size/2+t*20)); } } + StartY += 8.0f; } } else @@ -191,25 +205,33 @@ Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f); else Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.25f); - RenderTools()->DrawRoundRectExt(Whole-ScoreWidthMax-ImageSize-2*Split-PosSize, 245.0f+t*20, ScoreWidthMax+ImageSize+2*Split+PosSize, 18.0f, 5.0f, CUI::CORNER_L); + RenderTools()->DrawRoundRectExt(Whole-ScoreWidthMax-ImageSize-2*Split-PosSize, StartY+t*20, ScoreWidthMax+ImageSize+2*Split+PosSize, 18.0f, 5.0f, CUI::CORNER_L); Graphics()->QuadsEnd(); // draw score - TextRender()->Text(0, Whole-ScoreWidthMax+(ScoreWidthMax-aScoreWidth[t])/2-Split, 245.0f+t*20, 14.0f, aScore[t], -1); + TextRender()->Text(0, Whole-ScoreWidthMax+(ScoreWidthMax-aScoreWidth[t])/2-Split, StartY+t*20, 14.0f, aScore[t], -1); - // draw tee if(apPlayerInfo[t]) { - CTeeRenderInfo Info = m_pClient->m_aClients[apPlayerInfo[t]->m_ClientID].m_RenderInfo; + // draw name + int ID = apPlayerInfo[t]->m_ClientID; + const char *pName = m_pClient->m_aClients[ID].m_aName; + float w = TextRender()->TextWidth(0, 8.0f, pName, -1); + TextRender()->Text(0, min(Whole-w-1.0f, Whole-ScoreWidthMax-ImageSize-2*Split-PosSize), StartY+(t+1)*20.0f-3.0f, 8.0f, pName, -1); + + // draw tee + CTeeRenderInfo Info = m_pClient->m_aClients[ID].m_RenderInfo; Info.m_Size = 18.0f; RenderTools()->RenderTee(CAnimState::GetIdle(), &Info, EMOTE_NORMAL, vec2(1,0), - vec2(Whole-ScoreWidthMax-Info.m_Size/2-Split, 246.0f+Info.m_Size/2+t*20)); + vec2(Whole-ScoreWidthMax-Info.m_Size/2-Split, StartY+1.0f+Info.m_Size/2+t*20)); } // draw position char aBuf[32]; str_format(aBuf, sizeof(aBuf), "%d.", aPos[t]); - TextRender()->Text(0, Whole-ScoreWidthMax-ImageSize-Split-PosSize, 247.0f+t*20, 10.0f, aBuf, -1); + TextRender()->Text(0, Whole-ScoreWidthMax-ImageSize-Split-PosSize, StartY+2.0f+t*20, 10.0f, aBuf, -1); + + StartY += 8.0f; } } } @@ -248,7 +270,7 @@ if(g_Config.m_ClShowfps) { // calculate avg. fps - float FPS = 1.0f / Client()->FrameTime(); + float FPS = 1.0f / Client()->RenderFrameTime(); m_AverageFPS = (m_AverageFPS*(1.0f-(1.0f/m_AverageFPS))) + (FPS*(1.0f/m_AverageFPS)); char Buf[512]; str_format(Buf, sizeof(Buf), "%d", (int)m_AverageFPS); @@ -440,6 +462,7 @@ } RenderGameTimer(); + RenderPauseNotification(); RenderSuddenDeath(); RenderScoreHud(); RenderWarmupTimer(); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/hud.h teeworlds-0.6.2+dfsg/src/game/client/components/hud.h --- teeworlds-0.6.1+dfsg/src/game/client/components/hud.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/hud.h 2013-05-01 11:47:39.000000000 +0000 @@ -17,6 +17,7 @@ void RenderVoting(); void RenderHealthAndAmmo(const CNetObj_Character *pCharacter); void RenderGameTimer(); + void RenderPauseNotification(); void RenderSuddenDeath(); void RenderScoreHud(); void RenderSpectatorHud(); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/items.cpp teeworlds-0.6.2+dfsg/src/game/client/components/items.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/items.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/items.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -17,12 +17,11 @@ void CItems::OnReset() { - ExtraProjectilesNum = 0; + m_NumExtraProjectiles = 0; } void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID) { - // get positions float Curvature = 0; float Speed = 0; @@ -42,7 +41,10 @@ Speed = m_pClient->m_Tuning.m_GunSpeed; } - float Ct = (Client()->PrevGameTick()-pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + Client()->GameTickTime(); + static float s_LastGameTickTime = Client()->GameTickTime(); + if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) + s_LastGameTickTime = Client()->GameTickTime(); + float Ct = (Client()->PrevGameTick()-pCurrent->m_StartTick)/(float)SERVER_TICK_SPEED + s_LastGameTickTime; if(Ct < 0) return; // projectile havn't been shot yet @@ -64,28 +66,27 @@ if(pCurrent->m_Type == WEAPON_GRENADE) { m_pClient->m_pEffects->SmokeTrail(Pos, Vel*-1); - m_pClient->m_pFlow->Add(Pos, Vel*1000*Client()->FrameTime(), 10.0f); + static float s_Time = 0.0f; + static float s_LastLocalTime = Client()->LocalTime(); if(Client()->State() == IClient::STATE_DEMOPLAYBACK) { const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); - static float Time = 0; - static float LastLocalTime = Client()->LocalTime(); - if(!pInfo->m_Paused) - Time += (Client()->LocalTime()-LastLocalTime)*pInfo->m_Speed; - - Graphics()->QuadsSetRotation(Time*pi*2*2 + ItemID); - - LastLocalTime = Client()->LocalTime(); + s_Time += (Client()->LocalTime()-s_LastLocalTime)*pInfo->m_Speed; } else - Graphics()->QuadsSetRotation(Client()->LocalTime()*pi*2*2 + ItemID); + { + if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) + s_Time += Client()->LocalTime()-s_LastLocalTime; + } + + Graphics()->QuadsSetRotation(s_Time*pi*2*2 + ItemID); + s_LastLocalTime = Client()->LocalTime(); } else { m_pClient->m_pEffects->BulletTrail(Pos); - m_pClient->m_pFlow->Add(Pos, Vel*1000*Client()->FrameTime(), 10.0f); if(length(Vel) > 0.00001f) Graphics()->QuadsSetRotation(GetAngle(Vel)); @@ -133,26 +134,23 @@ Graphics()->QuadsSetRotation(Angle); + static float s_Time = 0.0f; + static float s_LastLocalTime = Client()->LocalTime(); float Offset = Pos.y/32.0f + Pos.x/32.0f; if(Client()->State() == IClient::STATE_DEMOPLAYBACK) { const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); - static float Time = 0; - static float LastLocalTime = Client()->LocalTime(); - if(!pInfo->m_Paused) - Time += (Client()->LocalTime()-LastLocalTime)*pInfo->m_Speed; - - Pos.x += cosf(Time*2.0f+Offset)*2.5f; - Pos.y += sinf(Time*2.0f+Offset)*2.5f; - - LastLocalTime = Client()->LocalTime(); + s_Time += (Client()->LocalTime()-s_LastLocalTime)*pInfo->m_Speed; } else { - Pos.x += cosf(Client()->LocalTime()*2.0f+Offset)*2.5f; - Pos.y += sinf(Client()->LocalTime()*2.0f+Offset)*2.5f; - } + if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) + s_Time += Client()->LocalTime()-s_LastLocalTime; + } + Pos.x += cosf(s_Time*2.0f+Offset)*2.5f; + Pos.y += sinf(s_Time*2.0f+Offset)*2.5f; + s_LastLocalTime = Client()->LocalTime(); RenderTools()->DrawSprite(Pos.x, Pos.y, Size); Graphics()->QuadsEnd(); } @@ -310,23 +308,23 @@ } // render extra projectiles - for(int i = 0; i < ExtraProjectilesNum; i++) + for(int i = 0; i < m_NumExtraProjectiles; i++) { - if(aExtraProjectiles[i].m_StartTick < Client()->GameTick()) + if(m_aExtraProjectiles[i].m_StartTick < Client()->GameTick()) { - aExtraProjectiles[i] = aExtraProjectiles[ExtraProjectilesNum-1]; - ExtraProjectilesNum--; + m_aExtraProjectiles[i] = m_aExtraProjectiles[m_NumExtraProjectiles-1]; + m_NumExtraProjectiles--; } else - RenderProjectile(&aExtraProjectiles[i], 0); + RenderProjectile(&m_aExtraProjectiles[i], 0); } } void CItems::AddExtraProjectile(CNetObj_Projectile *pProj) { - if(ExtraProjectilesNum != MAX_EXTRA_PROJECTILES) + if(m_NumExtraProjectiles != MAX_EXTRA_PROJECTILES) { - aExtraProjectiles[ExtraProjectilesNum] = *pProj; - ExtraProjectilesNum++; + m_aExtraProjectiles[m_NumExtraProjectiles] = *pProj; + m_NumExtraProjectiles++; } } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/items.h teeworlds-0.6.2+dfsg/src/game/client/components/items.h --- teeworlds-0.6.1+dfsg/src/game/client/components/items.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/items.h 2013-05-01 11:47:39.000000000 +0000 @@ -11,8 +11,8 @@ MAX_EXTRA_PROJECTILES=32, }; - CNetObj_Projectile aExtraProjectiles[MAX_EXTRA_PROJECTILES]; - int ExtraProjectilesNum; + CNetObj_Projectile m_aExtraProjectiles[MAX_EXTRA_PROJECTILES]; + int m_NumExtraProjectiles; void RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID); void RenderPickup(const CNetObj_Pickup *pPrev, const CNetObj_Pickup *pCurrent); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/maplayers.cpp teeworlds-0.6.2+dfsg/src/game/client/components/maplayers.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/maplayers.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/maplayers.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -22,6 +22,9 @@ { m_Type = t; m_pLayers = 0; + m_CurrentLocalTick = 0; + m_LastLocalTick = 0; + m_EnvelopeUpdate = false; } void CMapLayers::OnInit() @@ -29,6 +32,17 @@ m_pLayers = Layers(); } +void CMapLayers::EnvelopeUpdate() +{ + if(Client()->State() == IClient::STATE_DEMOPLAYBACK) + { + const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); + m_CurrentLocalTick = pInfo->m_CurrentTick; + m_LastLocalTick = pInfo->m_CurrentTick; + m_EnvelopeUpdate = true; + } +} + void CMapLayers::MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup) { @@ -63,24 +77,42 @@ CMapItemEnvelope *pItem = (CMapItemEnvelope *)pThis->m_pLayers->Map()->GetItem(Start+Env, 0, 0); - static float Time = 0; + static float s_Time = 0.0f; + static float s_LastLocalTime = pThis->Client()->LocalTime(); if(pThis->Client()->State() == IClient::STATE_DEMOPLAYBACK) { const IDemoPlayer::CInfo *pInfo = pThis->DemoPlayer()->BaseInfo(); - static int LastLocalTick = pInfo->m_CurrentTick; - - if(!pInfo->m_Paused) - Time += (pInfo->m_CurrentTick-LastLocalTick) / (float)pThis->Client()->GameTickSpeed() * pInfo->m_Speed; + + if(!pInfo->m_Paused || pThis->m_EnvelopeUpdate) + { + if(pThis->m_CurrentLocalTick != pInfo->m_CurrentTick) + { + pThis->m_LastLocalTick = pThis->m_CurrentLocalTick; + pThis->m_CurrentLocalTick = pInfo->m_CurrentTick; + } - pThis->RenderTools()->RenderEvalEnvelope(pPoints+pItem->m_StartPoint, pItem->m_NumPoints, 4, Time+TimeOffset, pChannels); + s_Time = mix(pThis->m_LastLocalTick / (float)pThis->Client()->GameTickSpeed(), + pThis->m_CurrentLocalTick / (float)pThis->Client()->GameTickSpeed(), + pThis->Client()->IntraGameTick()); + } - LastLocalTick = pInfo->m_CurrentTick; + pThis->RenderTools()->RenderEvalEnvelope(pPoints+pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels); } else { - if(pThis->m_pClient->m_Snap.m_pGameInfoObj) - Time = (pThis->Client()->GameTick()-pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick) / (float)pThis->Client()->GameTickSpeed(); - pThis->RenderTools()->RenderEvalEnvelope(pPoints+pItem->m_StartPoint, pItem->m_NumPoints, 4, Time+TimeOffset, pChannels); + if(pThis->m_pClient->m_Snap.m_pGameInfoObj && !(pThis->m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) + { + if(pItem->m_Version < 2 || pItem->m_Synchronized) + { + s_Time = mix((pThis->Client()->PrevGameTick()-pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick) / (float)pThis->Client()->GameTickSpeed(), + (pThis->Client()->GameTick()-pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick) / (float)pThis->Client()->GameTickSpeed(), + pThis->Client()->IntraGameTick()); + } + else + s_Time += pThis->Client()->LocalTime()-s_LastLocalTime; + } + pThis->RenderTools()->RenderEvalEnvelope(pPoints+pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels); + s_LastLocalTime = pThis->Client()->LocalTime(); } } @@ -160,16 +192,11 @@ IOHANDLE File = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); if(File) { - #if defined(CONF_FAMILY_WINDOWS) - static const char Newline[] = "\r\n"; - #else - static const char Newline[] = "\n"; - #endif for(int y = 0; y < pTMap->m_Height; y++) { for(int x = 0; x < pTMap->m_Width; x++) io_write(File, &(pTiles[y*pTMap->m_Width + x].m_Index), sizeof(pTiles[y*pTMap->m_Width + x].m_Index)); - io_write(File, Newline, sizeof(Newline)-1); + io_write_newline(File); } io_close(File); } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/maplayers.h teeworlds-0.6.2+dfsg/src/game/client/components/maplayers.h --- teeworlds-0.6.1+dfsg/src/game/client/components/maplayers.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/maplayers.h 2013-05-01 11:47:39.000000000 +0000 @@ -8,6 +8,9 @@ { CLayers *m_pLayers; // todo refactor: maybe remove it and access it through client* int m_Type; + int m_CurrentLocalTick; + int m_LastLocalTick; + bool m_EnvelopeUpdate; void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup); static void EnvelopeEval(float TimeOffset, int Env, float *pChannels, void *pUser); @@ -21,6 +24,8 @@ CMapLayers(int Type); virtual void OnInit(); virtual void OnRender(); + + void EnvelopeUpdate(); }; #endif diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/menus.cpp teeworlds-0.6.2+dfsg/src/game/client/components/menus.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/menus.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/menus.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -35,11 +35,10 @@ vec4 CMenus::ms_ColorTabbarInactiveOutgame; vec4 CMenus::ms_ColorTabbarActiveOutgame; vec4 CMenus::ms_ColorTabbarInactive; -vec4 CMenus::ms_ColorTabbarActive; +vec4 CMenus::ms_ColorTabbarActive = vec4(0,0,0,0.5f); vec4 CMenus::ms_ColorTabbarInactiveIngame; vec4 CMenus::ms_ColorTabbarActiveIngame; - float CMenus::ms_ButtonHeight = 25.0f; float CMenus::ms_ListheaderHeight = 17.0f; float CMenus::ms_FontmodHeight = 0.8f; @@ -95,14 +94,16 @@ return 0; } -int CMenus::DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect) +int CMenus::DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active) { Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GUIBUTTONS].m_Id); Graphics()->QuadsBegin(); + if(!Active) + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.5f); RenderTools()->SelectSprite(Checked?SPRITE_GUIBUTTON_ON:SPRITE_GUIBUTTON_OFF); IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h); Graphics()->QuadsDrawTL(&QuadItem, 1); - if((UI()->HotItem() == pID)) + if(UI()->HotItem() == pID && Active) { RenderTools()->SelectSprite(SPRITE_GUIBUTTON_HOVER); IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h); @@ -110,7 +111,7 @@ } Graphics()->QuadsEnd(); - return UI()->DoButtonLogic(pID, "", Checked, pRect); + return Active ? UI()->DoButtonLogic(pID, "", Checked, pRect) : 0; } int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect) @@ -242,7 +243,8 @@ for(int i = 0; i < m_NumInputEvents; i++) { Len = str_length(pStr); - ReturnValue |= CLineInput::Manipulate(m_aInputEvents[i], pStr, StrSize, &Len, &s_AtIndex); + int NumChars = Len; + ReturnValue |= CLineInput::Manipulate(m_aInputEvents[i], pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars); } } @@ -628,6 +630,8 @@ void CMenus::RenderLoading() { + // TODO: not supported right now due to separate render thread + static int64 LastLoadRender = 0; float Percent = m_LoadCurrent++/(float)m_LoadTotal; @@ -1042,7 +1046,7 @@ } // update download speed - float Diff = Client()->MapDownloadAmount()-m_DownloadLastCheckSize; + float Diff = (Client()->MapDownloadAmount()-m_DownloadLastCheckSize)/((int)((Now-m_DownloadLastCheckTime)/time_freq())); float StartDiff = m_DownloadLastCheckSize-0.0f; if(StartDiff+Diff > 0.0f) m_DownloadSpeed = (Diff/(StartDiff+Diff))*(Diff/1.0f) + (StartDiff/(Diff+StartDiff))*m_DownloadSpeed; @@ -1108,7 +1112,7 @@ Box.HSplitBottom(24.f, &Box, &Part); Box.HSplitBottom(20.f, &Box, 0); Box.VMargin(20.0f, &Box); - + static int ActSelection = -2; if(ActSelection == -2) ActSelection = g_Config.m_BrFilterCountryIndex; @@ -1131,12 +1135,8 @@ float OldWidth = Item.m_Rect.w; Item.m_Rect.w = Item.m_Rect.h*2; Item.m_Rect.x += (OldWidth-Item.m_Rect.w)/ 2.0f; - Graphics()->TextureSet(pEntry->m_Texture); - Graphics()->QuadsBegin(); - Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); - IGraphics::CQuadItem QuadItem(Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h); - Graphics()->QuadsDrawTL(&QuadItem, 1); - Graphics()->QuadsEnd(); + vec4 Color(1.0f, 1.0f, 1.0f, 1.0f); + m_pClient->m_pCountryFlags->Render(pEntry->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h); UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0); } } @@ -1312,6 +1312,9 @@ if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed) m_Popup = POPUP_NONE; } + + if(m_Popup == POPUP_NONE) + UI()->SetActiveItem(0); } return 0; @@ -1402,8 +1405,8 @@ if(NewState == IClient::STATE_OFFLINE) { - if(OldState >= IClient::STATE_ONLINE) - m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0)); + if(OldState >= IClient::STATE_ONLINE && NewState < IClient::STATE_QUITING) + m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f); m_Popup = POPUP_NONE; if(Client()->ErrorString() && Client()->ErrorString()[0] != 0) { diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/menus.h teeworlds-0.6.2+dfsg/src/game/client/components/menus.h --- teeworlds-0.6.1+dfsg/src/game/client/components/menus.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/menus.h 2013-05-01 11:47:39.000000000 +0000 @@ -40,7 +40,7 @@ int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect); int DoButton_Sprite(const void *pID, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners); - int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect); + int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active); int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect); int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/menus_browser.cpp teeworlds-0.6.2+dfsg/src/game/client/components/menus_browser.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/menus_browser.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/menus_browser.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -225,7 +225,7 @@ { int ItemIndex = i; const CServerInfo *pItem = ServerBrowser()->SortedGet(ItemIndex); - NumPlayers += pItem->m_NumPlayers; + NumPlayers += g_Config.m_BrFilterSpectators ? pItem->m_NumPlayers : pItem->m_NumClients; CUIRect Row; CUIRect SelectHitBox; @@ -516,7 +516,7 @@ ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterPureMap, Localize("Standard map"), g_Config.m_BrFilterPureMap, &Button)) g_Config.m_BrFilterPureMap ^= 1; - + ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter); if (DoButton_CheckBox((char *)&g_Config.m_BrFilterGametypeStrict, Localize("Strict gametype filter"), g_Config.m_BrFilterGametypeStrict, &Button)) g_Config.m_BrFilterGametypeStrict ^= 1; @@ -563,16 +563,12 @@ Button.HMargin(3.0f, &Button); if(DoButton_CheckBox(&g_Config.m_BrFilterCountry, Localize("Player country:"), g_Config.m_BrFilterCountry, &Button)) g_Config.m_BrFilterCountry ^= 1; - + float OldWidth = Rect.w; Rect.w = Rect.h*2; Rect.x += (OldWidth-Rect.w)/2.0f; - Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(g_Config.m_BrFilterCountryIndex)->m_Texture); - Graphics()->QuadsBegin(); - Graphics()->SetColor(1.0f, 1.0f, 1.0f, g_Config.m_BrFilterCountry?1.0f: 0.5f); - IGraphics::CQuadItem QuadItem(Rect.x, Rect.y, Rect.w, Rect.h); - Graphics()->QuadsDrawTL(&QuadItem, 1); - Graphics()->QuadsEnd(); + vec4 Color(1.0f, 1.0f, 1.0f, g_Config.m_BrFilterCountry?1.0f: 0.5f); + m_pClient->m_pCountryFlags->Render(g_Config.m_BrFilterCountryIndex, &Color, Rect.x, Rect.y, Rect.w, Rect.h); if(g_Config.m_BrFilterCountry && UI()->DoButtonLogic(&g_Config.m_BrFilterCountryIndex, "", 0, &Rect)) m_Popup = POPUP_COUNTRY; @@ -766,12 +762,8 @@ TextRender()->TextEx(&Cursor, pClan, -1); // flag - Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(pSelectedServer->m_aClients[i].m_Country)->m_Texture); - Graphics()->QuadsBegin(); - Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.5f); - IGraphics::CQuadItem QuadItem(Flag.x, Flag.y, Flag.w, Flag.h); - Graphics()->QuadsDrawTL(&QuadItem, 1); - Graphics()->QuadsEnd(); + vec4 Color(1.0f, 1.0f, 1.0f, 0.5f); + m_pClient->m_pCountryFlags->Render(pSelectedServer->m_aClients[i].m_Country, &Color, Flag.x, Flag.y, Flag.w, Flag.h); } } } @@ -814,6 +806,8 @@ // friends list(remove friend) static float s_ScrollValue = 0; + if(m_FriendlistSelectedIndex >= m_lFriends.size()) + m_FriendlistSelectedIndex = m_lFriends.size()-1; UiDoListboxStart(&m_lFriends, &List, 30.0f, "", "", m_lFriends.size(), 1, m_FriendlistSelectedIndex, s_ScrollValue); m_lFriends.sort_range(); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/menus_demo.cpp teeworlds-0.6.2+dfsg/src/game/client/components/menus_demo.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/menus_demo.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/menus_demo.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -17,6 +17,7 @@ #include +#include "maplayers.h" #include "menus.h" int CMenus::DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect) @@ -85,15 +86,28 @@ void *id = &s_SeekBarID; char aBuffer[128]; + // draw seek bar RenderTools()->DrawUIRect(&SeekBar, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 5.0f); + // draw filled bar float Amount = CurrentTick/(float)TotalTicks; - CUIRect FilledBar = SeekBar; FilledBar.w = 10.0f + (FilledBar.w-10.0f)*Amount; - RenderTools()->DrawUIRect(&FilledBar, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 5.0f); + // draw markers + for(int i = 0; i < pInfo->m_NumTimelineMarkers; i++) + { + float Ratio = (pInfo->m_aTimelineMarkers[i]-pInfo->m_FirstTick) / (float)TotalTicks; + Graphics()->TextureSet(-1); + Graphics()->QuadsBegin(); + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + IGraphics::CQuadItem QuadItem(SeekBar.x + (SeekBar.w-10.0f)*Ratio, SeekBar.y, UI()->PixelSize(), SeekBar.h); + Graphics()->QuadsDrawTL(&QuadItem, 1); + Graphics()->QuadsEnd(); + } + + // draw time str_format(aBuffer, sizeof(aBuffer), "%d:%02d / %d:%02d", CurrentTick/SERVER_TICK_SPEED/60, (CurrentTick/SERVER_TICK_SPEED)%60, TotalTicks/SERVER_TICK_SPEED/60, (TotalTicks/SERVER_TICK_SPEED)%60); @@ -117,6 +131,8 @@ m_pClient->m_SuppressEvents = true; DemoPlayer()->SetPos(Amount); m_pClient->m_SuppressEvents = false; + m_pClient->m_pMapLayersBackGround->EnvelopeUpdate(); + m_pClient->m_pMapLayersForeGround->EnvelopeUpdate(); } } } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/menus_ingame.cpp teeworlds-0.6.2+dfsg/src/game/client/components/menus_ingame.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/menus_ingame.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/menus_ingame.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -149,7 +149,11 @@ static int s_aPlayerIDs[MAX_CLIENTS][2] = {{0}}; for(int i = 0, Count = 0; i < MAX_CLIENTS; ++i) { - if(!m_pClient->m_Snap.m_paPlayerInfos[i] || i == m_pClient->m_Snap.m_LocalClientID) + if(!m_pClient->m_Snap.m_paInfoByTeam[i]) + continue; + + int Index = m_pClient->m_Snap.m_paInfoByTeam[i]->m_ClientID; + if(Index == m_pClient->m_Snap.m_LocalClientID) continue; Options.HSplitTop(28.0f, &ButtonBar, &Options); @@ -159,7 +163,7 @@ // player info Player.VSplitLeft(28.0f, &Button, &Player); - CTeeRenderInfo Info = m_pClient->m_aClients[i].m_RenderInfo; + CTeeRenderInfo Info = m_pClient->m_aClients[Index].m_RenderInfo; Info.m_Size = Button.h; RenderTools()->RenderTee(CAnimState::GetIdle(), &Info, EMOTE_NORMAL, vec2(1.0f, 0.0f), vec2(Button.x+Button.h/2, Button.y+Button.h/2)); @@ -168,31 +172,34 @@ CTextCursor Cursor; TextRender()->SetCursor(&Cursor, Player.x, Player.y, 14.0f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); Cursor.m_LineWidth = Player.w; - TextRender()->TextEx(&Cursor, m_pClient->m_aClients[i].m_aName, -1); + TextRender()->TextEx(&Cursor, m_pClient->m_aClients[Index].m_aName, -1); TextRender()->SetCursor(&Cursor, Button.x,Button.y, 14.0f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); Cursor.m_LineWidth = Button.w; - TextRender()->TextEx(&Cursor, m_pClient->m_aClients[i].m_aClan, -1); + TextRender()->TextEx(&Cursor, m_pClient->m_aClients[Index].m_aClan, -1); // ignore button ButtonBar.HMargin(2.0f, &ButtonBar); ButtonBar.VSplitLeft(Width, &Button, &ButtonBar); Button.VSplitLeft((Width-Button.h)/4.0f, 0, &Button); Button.VSplitLeft(Button.h, &Button, 0); - if(DoButton_Toggle(&s_aPlayerIDs[i][0], m_pClient->m_aClients[i].m_ChatIgnore, &Button)) - m_pClient->m_aClients[i].m_ChatIgnore ^= 1; + if(g_Config.m_ClShowChatFriends && !m_pClient->m_aClients[Index].m_Friend) + DoButton_Toggle(&s_aPlayerIDs[Index][0], 1, &Button, false); + else + if(DoButton_Toggle(&s_aPlayerIDs[Index][0], m_pClient->m_aClients[Index].m_ChatIgnore, &Button, true)) + m_pClient->m_aClients[Index].m_ChatIgnore ^= 1; // friend button ButtonBar.VSplitLeft(20.0f, &Button, &ButtonBar); ButtonBar.VSplitLeft(Width, &Button, &ButtonBar); Button.VSplitLeft((Width-Button.h)/4.0f, 0, &Button); Button.VSplitLeft(Button.h, &Button, 0); - if(DoButton_Toggle(&s_aPlayerIDs[i][1], m_pClient->m_aClients[i].m_Friend, &Button)) + if(DoButton_Toggle(&s_aPlayerIDs[Index][1], m_pClient->m_aClients[Index].m_Friend, &Button, true)) { - if(m_pClient->m_aClients[i].m_Friend) - m_pClient->Friends()->RemoveFriend(m_pClient->m_aClients[i].m_aName, m_pClient->m_aClients[i].m_aClan); + if(m_pClient->m_aClients[Index].m_Friend) + m_pClient->Friends()->RemoveFriend(m_pClient->m_aClients[Index].m_aName, m_pClient->m_aClients[Index].m_aClan); else - m_pClient->Friends()->AddFriend(m_pClient->m_aClients[i].m_aName, m_pClient->m_aClients[i].m_aClan); + m_pClient->Friends()->AddFriend(m_pClient->m_aClients[Index].m_aName, m_pClient->m_aClients[Index].m_aClan); } } @@ -385,13 +392,15 @@ static int aPlayerIDs[MAX_CLIENTS]; for(int i = 0; i < MAX_CLIENTS; i++) { - if(!m_pClient->m_Snap.m_paPlayerInfos[i] || i == m_pClient->m_Snap.m_LocalClientID) + if(!m_pClient->m_Snap.m_paInfoByTeam[i]) continue; - if(FilterSpectators && m_pClient->m_Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS) + + int Index = m_pClient->m_Snap.m_paInfoByTeam[i]->m_ClientID; + if(Index == m_pClient->m_Snap.m_LocalClientID || (FilterSpectators && m_pClient->m_Snap.m_paInfoByTeam[i]->m_Team == TEAM_SPECTATORS)) continue; - if(m_CallvoteSelectedPlayer == i) + if(m_CallvoteSelectedPlayer == Index) Selected = NumOptions; - aPlayerIDs[NumOptions++] = i; + aPlayerIDs[NumOptions++] = Index; } static int s_VoteList = 0; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/menus_settings.cpp teeworlds-0.6.2+dfsg/src/game/client/components/menus_settings.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/menus_settings.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/menus_settings.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -96,6 +96,12 @@ if(DoButton_CheckBox(&g_Config.m_ClShowhud, Localize("Show ingame HUD"), g_Config.m_ClShowhud, &Button)) g_Config.m_ClShowhud ^= 1; + // chat messages + Left.HSplitTop(5.0f, 0, &Left); + Left.HSplitTop(20.0f, &Button, &Left); + if(DoButton_CheckBox(&g_Config.m_ClShowChatFriends, Localize("Show only chat messages from friends"), g_Config.m_ClShowChatFriends, &Button)) + g_Config.m_ClShowChatFriends ^= 1; + // name plates Right.HSplitTop(20.0f, &Button, &Right); if(DoButton_CheckBox(&g_Config.m_ClNameplates, Localize("Show name plates"), g_Config.m_ClNameplates, &Button)) @@ -221,13 +227,10 @@ float OldWidth = Item.m_Rect.w; Item.m_Rect.w = Item.m_Rect.h*2; Item.m_Rect.x += (OldWidth-Item.m_Rect.w)/ 2.0f; - Graphics()->TextureSet(pEntry->m_Texture); - Graphics()->QuadsBegin(); - Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); - IGraphics::CQuadItem QuadItem(Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h); - Graphics()->QuadsDrawTL(&QuadItem, 1); - Graphics()->QuadsEnd(); - UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0); + vec4 Color(1.0f, 1.0f, 1.0f, 1.0f); + m_pClient->m_pCountryFlags->Render(pEntry->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h); + if(pEntry->m_Texture != -1) + UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0); } } @@ -446,13 +449,14 @@ { "Remote console", "toggle_remote_console", 0 }, { "Screenshot", "screenshot", 0 }, { "Scoreboard", "+scoreboard", 0 }, + { "Respawn", "kill", 0 }, }; /* This is for scripts/update_localization.py to work, don't remove! Localize("Move left");Localize("Move right");Localize("Jump");Localize("Fire");Localize("Hook");Localize("Hammer"); Localize("Pistol");Localize("Shotgun");Localize("Grenade");Localize("Rifle");Localize("Next weapon");Localize("Prev. weapon"); Localize("Vote yes");Localize("Vote no");Localize("Chat");Localize("Team chat");Localize("Show chat");Localize("Emoticon"); - Localize("Spectator mode");Localize("Spectate next");Localize("Spectate previous");Localize("Console");Localize("Remote console");Localize("Screenshot");Localize("Scoreboard"); + Localize("Spectator mode");Localize("Spectate next");Localize("Spectate previous");Localize("Console");Localize("Remote console");Localize("Screenshot");Localize("Scoreboard");Localize("Respawn"); */ const int g_KeyCount = sizeof(gs_aKeys) / sizeof(CKeyInfo); @@ -504,10 +508,11 @@ } CUIRect MovementSettings, WeaponSettings, VotingSettings, ChatSettings, MiscSettings, ResetButton; - MainView.VSplitLeft(MainView.w/2-5.0f, &MovementSettings, &VotingSettings); + MainView.VSplitMid(&MovementSettings, &VotingSettings); // movement settings { + MovementSettings.VMargin(5.0f, &MovementSettings); MovementSettings.HSplitTop(MainView.h/3+60.0f, &MovementSettings, &WeaponSettings); RenderTools()->DrawUIRect(&MovementSettings, vec4(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f); MovementSettings.Margin(10.0f, &MovementSettings); @@ -543,21 +548,22 @@ WeaponSettings.HSplitTop(14.0f+5.0f+10.0f, 0, &WeaponSettings); UiDoGetButtons(5, 12, WeaponSettings); } - + // defaults { ResetButton.HSplitTop(10.0f, 0, &ResetButton); RenderTools()->DrawUIRect(&ResetButton, vec4(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f); ResetButton.HMargin(10.0f, &ResetButton); ResetButton.VMargin(30.0f, &ResetButton); + ResetButton.HSplitTop(20.0f, &ResetButton, 0); static int s_DefaultButton = 0; if(DoButton_Menu((void*)&s_DefaultButton, Localize("Reset to defaults"), 0, &ResetButton)) m_pClient->m_pBinds->SetDefaults(); } - + // voting settings { - VotingSettings.VSplitLeft(10.0f, 0, &VotingSettings); + VotingSettings.VMargin(5.0f, &VotingSettings); VotingSettings.HSplitTop(MainView.h/3-75.0f, &VotingSettings, &ChatSettings); RenderTools()->DrawUIRect(&VotingSettings, vec4(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f); VotingSettings.Margin(10.0f, &VotingSettings); @@ -590,7 +596,7 @@ TextRender()->Text(0, MiscSettings.x, MiscSettings.y, 14.0f*UI()->Scale(), Localize("Miscellaneous"), -1); MiscSettings.HSplitTop(14.0f+5.0f+10.0f, 0, &MiscSettings); - UiDoGetButtons(17, 25, MiscSettings); + UiDoGetButtons(17, 26, MiscSettings); } } @@ -607,11 +613,13 @@ static int s_GfxScreenWidth = g_Config.m_GfxScreenWidth; static int s_GfxScreenHeight = g_Config.m_GfxScreenHeight; static int s_GfxColorDepth = g_Config.m_GfxColorDepth; + static int s_GfxBorderless = g_Config.m_GfxBorderless; static int s_GfxFullscreen = g_Config.m_GfxFullscreen; static int s_GfxVsync = g_Config.m_GfxVsync; static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples; static int s_GfxTextureQuality = g_Config.m_GfxTextureQuality; static int s_GfxTextureCompression = g_Config.m_GfxTextureCompression; + static int s_GfxThreaded = g_Config.m_GfxThreaded; CUIRect ModeList; MainView.VSplitLeft(300.0f, &MainView, &ModeList); @@ -662,9 +670,20 @@ // switches MainView.HSplitTop(20.0f, &Button, &MainView); + if(DoButton_CheckBox(&g_Config.m_GfxBorderless, Localize("Borderless window"), g_Config.m_GfxBorderless, &Button)) + { + g_Config.m_GfxBorderless ^= 1; + if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen) + g_Config.m_GfxFullscreen = 0; + CheckSettings = true; + } + + MainView.HSplitTop(20.0f, &Button, &MainView); if(DoButton_CheckBox(&g_Config.m_GfxFullscreen, Localize("Fullscreen"), g_Config.m_GfxFullscreen, &Button)) { g_Config.m_GfxFullscreen ^= 1; + if(g_Config.m_GfxFullscreen && g_Config.m_GfxBorderless) + g_Config.m_GfxBorderless = 0; CheckSettings = true; } @@ -681,8 +700,25 @@ g_Config.m_GfxFsaaSamples = (g_Config.m_GfxFsaaSamples+1)%17; CheckSettings = true; } + + MainView.HSplitTop(20.0f, &Button, &MainView); + if(DoButton_CheckBox(&g_Config.m_GfxThreaded, Localize("Threaded rendering"), g_Config.m_GfxThreaded, &Button)) + { + g_Config.m_GfxThreaded ^= 1; + CheckSettings = true; + } - MainView.HSplitTop(40.0f, &Button, &MainView); + MainView.HSplitTop(20.0f, &Button, &MainView); + if(g_Config.m_GfxThreaded) + { + Button.VSplitLeft(20.0f, 0, &Button); + if(DoButton_CheckBox(&g_Config.m_GfxAsyncRender, Localize("Handle rendering async from updates"), g_Config.m_GfxAsyncRender, &Button)) + { + g_Config.m_GfxAsyncRender ^= 1; + CheckSettings = true; + } + } + MainView.HSplitTop(20.0f, &Button, &MainView); if(DoButton_CheckBox(&g_Config.m_GfxTextureQuality, Localize("Quality Textures"), g_Config.m_GfxTextureQuality, &Button)) { @@ -707,11 +743,13 @@ if(s_GfxScreenWidth == g_Config.m_GfxScreenWidth && s_GfxScreenHeight == g_Config.m_GfxScreenHeight && s_GfxColorDepth == g_Config.m_GfxColorDepth && + s_GfxBorderless == g_Config.m_GfxBorderless && s_GfxFullscreen == g_Config.m_GfxFullscreen && s_GfxVsync == g_Config.m_GfxVsync && s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples && s_GfxTextureQuality == g_Config.m_GfxTextureQuality && - s_GfxTextureCompression == g_Config.m_GfxTextureCompression) + s_GfxTextureCompression == g_Config.m_GfxTextureCompression && + s_GfxThreaded == g_Config.m_GfxThreaded) m_NeedRestartGraphics = false; else m_NeedRestartGraphics = true; @@ -761,7 +799,7 @@ if(g_Config.m_SndEnable) { if(g_Config.m_SndMusic) - m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0)); + m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f); } else m_pClient->m_pSounds->Stop(SOUND_MENU); @@ -775,16 +813,23 @@ if(DoButton_CheckBox(&g_Config.m_SndMusic, Localize("Play background music"), g_Config.m_SndMusic, &Button)) { g_Config.m_SndMusic ^= 1; - if(g_Config.m_SndMusic) - m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0)); - else - m_pClient->m_pSounds->Stop(SOUND_MENU); + if(Client()->State() == IClient::STATE_OFFLINE) + { + if(g_Config.m_SndMusic) + m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f); + else + m_pClient->m_pSounds->Stop(SOUND_MENU); + } } MainView.HSplitTop(20.0f, &Button, &MainView); if(DoButton_CheckBox(&g_Config.m_SndNonactiveMute, Localize("Mute when not active"), g_Config.m_SndNonactiveMute, &Button)) g_Config.m_SndNonactiveMute ^= 1; + MainView.HSplitTop(20.0f, &Button, &MainView); + if(DoButton_CheckBox(&g_Config.m_ClThreadsoundloading, Localize("Threaded sound loading"), g_Config.m_ClThreadsoundloading, &Button)) + g_Config.m_ClThreadsoundloading ^= 1; + // sample rate box { char aBuf[64]; @@ -917,11 +962,8 @@ Item.m_Rect.VSplitLeft(Item.m_Rect.h*2.0f, &Rect, &Item.m_Rect); Rect.VMargin(6.0f, &Rect); Rect.HMargin(3.0f, &Rect); - Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(r.front().m_CountryCode)->m_Texture); - Graphics()->QuadsBegin(); - IGraphics::CQuadItem QuadItem(Rect.x, Rect.y, Rect.w, Rect.h); - Graphics()->QuadsDrawTL(&QuadItem, 1); - Graphics()->QuadsEnd(); + vec4 Color(1.0f, 1.0f, 1.0f, 1.0f); + m_pClient->m_pCountryFlags->Render(r.front().m_CountryCode, &Color, Rect.x, Rect.y, Rect.w, Rect.h); Item.m_Rect.HSplitTop(2.0f, 0, &Item.m_Rect); UI()->DoLabelScaled(&Item.m_Rect, r.front().m_Name, 16.0f, -1); } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/particles.cpp teeworlds-0.6.2+dfsg/src/game/client/components/particles.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/particles.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/particles.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -43,6 +43,11 @@ if(pInfo->m_Paused) return; } + else + { + if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) + return; + } if (m_FirstFree == -1) return; @@ -142,7 +147,10 @@ Update((float)((t-LastTime)/(double)time_freq())*pInfo->m_Speed); } else - Update((float)((t-LastTime)/(double)time_freq())); + { + if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) + Update((float)((t-LastTime)/(double)time_freq())); + } LastTime = t; } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/players.cpp teeworlds-0.6.2+dfsg/src/game/client/components/players.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/players.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/players.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -95,30 +95,7 @@ Player = *pPlayerChar; CNetObj_PlayerInfo pInfo = *pPlayerInfo; - CTeeRenderInfo RenderInfo = m_pClient->m_aClients[pInfo.m_ClientID].m_RenderInfo; - - // check for teamplay modes - bool IsTeamplay = false; - if(m_pClient->m_Snap.m_pGameInfoObj) - IsTeamplay = (m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS) != 0; - - // check for ninja - if (Player.m_Weapon == WEAPON_NINJA) - { - // change the skin for the player to the ninja - int Skin = m_pClient->m_pSkins->Find("x_ninja"); - if(Skin != -1) - { - if(IsTeamplay) - RenderInfo.m_Texture = m_pClient->m_pSkins->Get(Skin)->m_ColorTexture; - else - { - RenderInfo.m_Texture = m_pClient->m_pSkins->Get(Skin)->m_OrgTexture; - RenderInfo.m_ColorBody = vec4(1,1,1,1); - RenderInfo.m_ColorFeet = vec4(1,1,1,1); - } - } - } + CTeeRenderInfo RenderInfo = m_aRenderInfo[pInfo.m_ClientID]; float IntraTick = Client()->IntraGameTick(); @@ -218,31 +195,9 @@ Player = *pPlayerChar; CNetObj_PlayerInfo pInfo = *pPlayerInfo; - CTeeRenderInfo RenderInfo = m_pClient->m_aClients[pInfo.m_ClientID].m_RenderInfo; + CTeeRenderInfo RenderInfo = m_aRenderInfo[pInfo.m_ClientID]; - // check for teamplay modes - bool IsTeamplay = false; bool NewTick = m_pClient->m_NewTick; - if(m_pClient->m_Snap.m_pGameInfoObj) - IsTeamplay = (m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS) != 0; - - // check for ninja - if (Player.m_Weapon == WEAPON_NINJA) - { - // change the skin for the player to the ninja - int Skin = m_pClient->m_pSkins->Find("x_ninja"); - if(Skin != -1) - { - if(IsTeamplay) - RenderInfo.m_Texture = m_pClient->m_pSkins->Get(Skin)->m_ColorTexture; - else - { - RenderInfo.m_Texture = m_pClient->m_pSkins->Get(Skin)->m_OrgTexture; - RenderInfo.m_ColorBody = vec4(1,1,1,1); - RenderInfo.m_ColorFeet = vec4(1,1,1,1); - } - } - } // set size RenderInfo.m_Size = 64.0f; @@ -330,14 +285,17 @@ else if(!WantOtherDir) State.Add(&g_pData->m_aAnimations[ANIM_WALK], WalkTime, 1.0f); + static float s_LastGameTickTime = Client()->GameTickTime(); + if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) + s_LastGameTickTime = Client()->GameTickTime(); if (Player.m_Weapon == WEAPON_HAMMER) { - float ct = (Client()->PrevGameTick()-Player.m_AttackTick)/(float)SERVER_TICK_SPEED + Client()->GameTickTime(); + float ct = (Client()->PrevGameTick()-Player.m_AttackTick)/(float)SERVER_TICK_SPEED + s_LastGameTickTime; State.Add(&g_pData->m_aAnimations[ANIM_HAMMER_SWING], clamp(ct*5.0f,0.0f,1.0f), 1.0f); } if (Player.m_Weapon == WEAPON_NINJA) { - float ct = (Client()->PrevGameTick()-Player.m_AttackTick)/(float)SERVER_TICK_SPEED + Client()->GameTickTime(); + float ct = (Client()->PrevGameTick()-Player.m_AttackTick)/(float)SERVER_TICK_SPEED + s_LastGameTickTime; State.Add(&g_pData->m_aAnimations[ANIM_NINJA_SWING], clamp(ct*2.0f,0.0f,1.0f), 1.0f); } @@ -347,7 +305,7 @@ static int64 SkidSoundTime = 0; if(time_get()-SkidSoundTime > time_freq()/10) { - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, Position); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, Position); SkidSoundTime = time_get(); } @@ -409,15 +367,22 @@ if ((Client()->GameTick()-Player.m_AttackTick) <= (SERVER_TICK_SPEED / 6) && g_pData->m_Weapons.m_aId[iw].m_NumSpriteMuzzles) { int IteX = rand() % g_pData->m_Weapons.m_aId[iw].m_NumSpriteMuzzles; + static int s_LastIteX = IteX; if(Client()->State() == IClient::STATE_DEMOPLAYBACK) { - static int s_LastIteX = IteX; const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); if(pInfo->m_Paused) IteX = s_LastIteX; else s_LastIteX = IteX; } + else + { + if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) + IteX = s_LastIteX; + else + s_LastIteX = IteX; + } if(g_pData->m_Weapons.m_aId[iw].m_aSpriteMuzzles[IteX]) { vec2 Dir = vec2(pPlayerChar->m_X,pPlayerChar->m_Y) - vec2(pPrevChar->m_X, pPrevChar->m_Y); @@ -438,7 +403,11 @@ { // TODO: should be an animation Recoil = 0; - float a = (Client()->GameTick()-Player.m_AttackTick+IntraTick)/5.0f; + static float s_LastIntraTick = IntraTick; + if(m_pClient->m_Snap.m_pGameInfoObj && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) + s_LastIntraTick = IntraTick; + + float a = (Client()->GameTick()-Player.m_AttackTick+s_LastIntraTick)/5.0f; if(a < 1) Recoil = sinf(a*pi); p = Position + Dir * g_pData->m_Weapons.m_aId[iw].m_Offsetx - Dir*Recoil*10.0f; @@ -460,6 +429,22 @@ } int IteX = rand() % g_pData->m_Weapons.m_aId[iw].m_NumSpriteMuzzles; + static int s_LastIteX = IteX; + if(Client()->State() == IClient::STATE_DEMOPLAYBACK) + { + const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); + if(pInfo->m_Paused) + IteX = s_LastIteX; + else + s_LastIteX = IteX; + } + else + { + if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) + IteX = s_LastIteX; + else + s_LastIteX = IteX; + } if (Alpha > 0.0f && g_pData->m_Weapons.m_aId[iw].m_aSpriteMuzzles[IteX]) { float OffsetY = -g_pData->m_Weapons.m_aId[iw].m_Muzzleoffsety; @@ -546,6 +531,31 @@ void CPlayers::OnRender() { + // update RenderInfo for ninja + bool IsTeamplay = false; + if(m_pClient->m_Snap.m_pGameInfoObj) + IsTeamplay = (m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS) != 0; + for(int i = 0; i < MAX_CLIENTS; ++i) + { + m_aRenderInfo[i] = m_pClient->m_aClients[i].m_RenderInfo; + if(m_pClient->m_Snap.m_aCharacters[i].m_Cur.m_Weapon == WEAPON_NINJA) + { + // change the skin for the player to the ninja + int Skin = m_pClient->m_pSkins->Find("x_ninja"); + if(Skin != -1) + { + if(IsTeamplay) + m_aRenderInfo[i].m_Texture = m_pClient->m_pSkins->Get(Skin)->m_ColorTexture; + else + { + m_aRenderInfo[i].m_Texture = m_pClient->m_pSkins->Get(Skin)->m_OrgTexture; + m_aRenderInfo[i].m_ColorBody = vec4(1,1,1,1); + m_aRenderInfo[i].m_ColorFeet = vec4(1,1,1,1); + } + } + } + } + // render other players in two passes, first pass we render the other, second pass we render our self for(int p = 0; p < 4; p++) { diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/players.h teeworlds-0.6.2+dfsg/src/game/client/components/players.h --- teeworlds-0.6.1+dfsg/src/game/client/components/players.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/players.h 2013-05-01 11:47:39.000000000 +0000 @@ -6,6 +6,7 @@ class CPlayers : public CComponent { + CTeeRenderInfo m_aRenderInfo[MAX_CLIENTS]; void RenderHand(class CTeeRenderInfo *pInfo, vec2 CenterPos, vec2 Dir, float AngleOffset, vec2 PostRotOffset); void RenderPlayer( const CNetObj_Character *pPrevChar, diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/scoreboard.cpp teeworlds-0.6.2+dfsg/src/game/client/components/scoreboard.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/scoreboard.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/scoreboard.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -273,12 +273,9 @@ TextRender()->TextEx(&Cursor, m_pClient->m_aClients[pInfo->m_ClientID].m_aClan, -1); // country flag - Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(m_pClient->m_aClients[pInfo->m_ClientID].m_Country)->m_Texture); - Graphics()->QuadsBegin(); - Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.5f); - IGraphics::CQuadItem QuadItem(CountryOffset, y+(Spacing+TeeSizeMod*5.0f)/2.0f, CountryLength, LineHeight-Spacing-TeeSizeMod*5.0f); - Graphics()->QuadsDrawTL(&QuadItem, 1); - Graphics()->QuadsEnd(); + vec4 Color(1.0f, 1.0f, 1.0f, 0.5f); + m_pClient->m_pCountryFlags->Render(m_pClient->m_aClients[pInfo->m_ClientID].m_Country, &Color, + CountryOffset, y+(Spacing+TeeSizeMod*5.0f)/2.0f, CountryLength, LineHeight-Spacing-TeeSizeMod*5.0f); // ping str_format(aBuf, sizeof(aBuf), "%d", clamp(pInfo->m_Latency, 0, 1000)); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/skins.cpp teeworlds-0.6.2+dfsg/src/game/client/components/skins.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/skins.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/skins.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -7,6 +7,7 @@ #include #include +#include #include "skins.h" @@ -103,8 +104,11 @@ // set skin data str_copy(Skin.m_aName, pName, min((int)sizeof(Skin.m_aName),l-3)); - str_format(aBuf, sizeof(aBuf), "load skin %s", Skin.m_aName); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf); + if(g_Config.m_Debug) + { + str_format(aBuf, sizeof(aBuf), "load skin %s", Skin.m_aName); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf); + } pSelf->m_aSkins.add(Skin); return 0; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/sounds.cpp teeworlds-0.6.2+dfsg/src/game/client/components/sounds.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/sounds.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/sounds.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -34,6 +34,30 @@ return 0; } + +int CSounds::GetSampleId(int SetId) +{ + if(!g_Config.m_SndEnable || !Sound()->IsSoundEnabled() || m_WaitForSoundJob || SetId < 0 || SetId >= g_pData->m_NumSounds) + return -1; + + CDataSoundset *pSet = &g_pData->m_aSounds[SetId]; + if(!pSet->m_NumSounds) + return -1; + + if(pSet->m_NumSounds == 1) + return pSet->m_aSounds[0].m_Id; + + // return random one + int Id; + do + { + Id = rand() % pSet->m_NumSounds; + } + while(Id == pSet->m_Last); + pSet->m_Last = Id; + return pSet->m_aSounds[Id].m_Id; +} + void CSounds::OnInit() { // setup sound channels @@ -98,7 +122,7 @@ int64 Now = time_get(); if(m_QueueWaitTime <= Now) { - Play(m_aQueue[0].m_Channel, m_aQueue[0].m_SetId, 1.0f, vec2(0,0)); + Play(m_aQueue[0].m_Channel, m_aQueue[0].m_SetId, 1.0f); m_QueueWaitTime = Now+time_freq()*3/10; // wait 300ms before playing the next one if(--m_QueuePos > 0) mem_move(m_aQueue, m_aQueue+1, m_QueuePos*sizeof(QueueEntry)); @@ -132,47 +156,48 @@ Msg.m_SoundID = SetId; Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD); - Play(Chn, SetId, Vol, Pos); + Play(Chn, SetId, Vol); } -void CSounds::Play(int Chn, int SetId, float Vol, vec2 Pos) +void CSounds::Play(int Chn, int SetId, float Vol) { - if(!g_Config.m_SndEnable || !Sound()->IsSoundEnabled() || (Chn == CHN_MUSIC && !g_Config.m_SndMusic) || m_WaitForSoundJob || SetId < 0 || SetId >= g_pData->m_NumSounds) + if(Chn == CHN_MUSIC && !g_Config.m_SndMusic) return; - CDataSoundset *pSet = &g_pData->m_aSounds[SetId]; - - if(!pSet->m_NumSounds) + int SampleId = GetSampleId(SetId); + if(SampleId == -1) return; - + int Flags = 0; if(Chn == CHN_MUSIC) Flags = ISound::FLAG_LOOP; - if(pSet->m_NumSounds == 1) - { - Sound()->PlayAt(Chn, pSet->m_aSounds[0].m_Id, Flags, Pos.x, Pos.y); + Sound()->Play(Chn, SampleId, Flags); +} + +void CSounds::PlayAt(int Chn, int SetId, float Vol, vec2 Pos) +{ + if(Chn == CHN_MUSIC && !g_Config.m_SndMusic) + return; + + int SampleId = GetSampleId(SetId); + if(SampleId == -1) return; - } - // play a random one - int Id; - do - { - Id = rand() % pSet->m_NumSounds; - } - while(Id == pSet->m_Last); - Sound()->PlayAt(Chn, pSet->m_aSounds[Id].m_Id, Flags, Pos.x, Pos.y); - pSet->m_Last = Id; + int Flags = 0; + if(Chn == CHN_MUSIC) + Flags = ISound::FLAG_LOOP; + + Sound()->PlayAt(Chn, SampleId, Flags, Pos.x, Pos.y); } void CSounds::Stop(int SetId) { if(m_WaitForSoundJob || SetId < 0 || SetId >= g_pData->m_NumSounds) return; - + CDataSoundset *pSet = &g_pData->m_aSounds[SetId]; - + for(int i = 0; i < pSet->m_NumSounds; i++) Sound()->Stop(pSet->m_aSounds[i].m_Id); } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/sounds.h teeworlds-0.6.2+dfsg/src/game/client/components/sounds.h --- teeworlds-0.6.1+dfsg/src/game/client/components/sounds.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/sounds.h 2013-05-01 11:47:39.000000000 +0000 @@ -19,6 +19,8 @@ int64 m_QueueWaitTime; class CJob m_SoundJob; bool m_WaitForSoundJob; + + int GetSampleId(int SetId); public: // sound channels @@ -37,7 +39,8 @@ void ClearQueue(); void Enqueue(int Channel, int SetId); - void Play(int Channel, int SetId, float Vol, vec2 Pos); + void Play(int Channel, int SetId, float Vol); + void PlayAt(int Channel, int SetId, float Vol, vec2 Pos); void PlayAndRecord(int Channel, int SetId, float Vol, vec2 Pos); void Stop(int SetId); }; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/components/voting.cpp teeworlds-0.6.2+dfsg/src/game/client/components/voting.cpp --- teeworlds-0.6.1+dfsg/src/game/client/components/voting.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/components/voting.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -120,7 +120,12 @@ CVoting::CVoting() { ClearOptions(); - OnReset(); + + m_Closetime = 0; + m_aDescription[0] = 0; + m_aReason[0] = 0; + m_Yes = m_No = m_Pass = m_Total = 0; + m_Voted = 0; } void CVoting::AddOption(const char *pDescription) @@ -164,6 +169,9 @@ void CVoting::OnReset() { + if(Client()->State() == IClient::STATE_LOADING) // do not reset active vote while connecting + return; + m_Closetime = 0; m_aDescription[0] = 0; m_aReason[0] = 0; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/gameclient.cpp teeworlds-0.6.2+dfsg/src/game/client/gameclient.cpp --- teeworlds-0.6.1+dfsg/src/game/client/gameclient.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/gameclient.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -95,7 +95,6 @@ { m_pEngine = Kernel()->RequestInterface(); m_pClient = Kernel()->RequestInterface(); - m_pGraphics = Kernel()->RequestInterface(); m_pTextRender = Kernel()->RequestInterface(); m_pSound = Kernel()->RequestInterface(); m_pInput = Kernel()->RequestInterface(); @@ -126,6 +125,8 @@ m_pVoting = &::gs_Voting; m_pScoreboard = &::gs_Scoreboard; m_pItems = &::gs_Items; + m_pMapLayersBackGround = &::gs_MapLayersBackGround; + m_pMapLayersForeGround = &::gs_MapLayersForeGround; // make a list of all the systems, make sure to add them in the corrent render order m_All.Add(m_pSkins); @@ -192,12 +193,10 @@ Console()->Register("force_vote", "ss?r", CFGFLAG_SERVER, 0, 0, "Force a voting option"); Console()->Register("clear_votes", "", CFGFLAG_SERVER, 0, 0, "Clears the voting options"); Console()->Register("vote", "r", CFGFLAG_SERVER, 0, 0, "Force a vote to yes/no"); + Console()->Register("swap_teams", "", CFGFLAG_SERVER, 0, 0, "Swap the current teams"); + Console()->Register("shuffle_teams", "", CFGFLAG_SERVER, 0, 0, "Shuffle the current teams"); - // propagate pointers - m_UI.SetGraphics(Graphics(), TextRender()); - m_RenderTools.m_pGraphics = Graphics(); - m_RenderTools.m_pUI = UI(); for(int i = 0; i < m_All.m_Num; i++) m_All.m_paComponents[i]->m_pClient = this; @@ -221,6 +220,13 @@ void CGameClient::OnInit() { + m_pGraphics = Kernel()->RequestInterface(); + + // propagate pointers + m_UI.SetGraphics(Graphics(), TextRender()); + m_RenderTools.m_pGraphics = Graphics(); + m_RenderTools.m_pUI = UI(); + int64 Start = time_get(); // set the language @@ -443,7 +449,7 @@ m_NewPredictedTick = false; // check if client info has to be resent - if(m_LastSendInfo && Client()->State() == IClient::STATE_ONLINE && !m_pMenus->IsActive() && m_LastSendInfo+time_freq()*5 < time_get()) + if(m_LastSendInfo && Client()->State() == IClient::STATE_ONLINE && m_Snap.m_LocalClientID >= 0 && !m_pMenus->IsActive() && m_LastSendInfo+time_freq()*6 < time_get()) { // resend if client info differs if(str_comp(g_Config.m_PlayerName, m_aClients[m_Snap.m_LocalClientID].m_aName) || @@ -545,7 +551,7 @@ pMsg->m_SoundID == SOUND_CTF_GRAB_PL) g_GameClient.m_pSounds->Enqueue(CSounds::CHN_GLOBAL, pMsg->m_SoundID); else - g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_SoundID, 1.0f, vec2(0,0)); + g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_SoundID, 1.0f); } } @@ -565,7 +571,7 @@ void CGameClient::OnGameOver() { - if(Client()->State() != IClient::STATE_DEMOPLAYBACK) + if(Client()->State() != IClient::STATE_DEMOPLAYBACK && g_Config.m_ClEditor == 0) Client()->AutoScreenshot_Start(); } @@ -620,7 +626,7 @@ else if(Item.m_Type == NETEVENTTYPE_SOUNDWORLD) { CNetEvent_SoundWorld *ev = (CNetEvent_SoundWorld *)pData; - g_GameClient.m_pSounds->Play(CSounds::CHN_WORLD, ev->m_SoundID, 1.0f, vec2(ev->m_X, ev->m_Y)); + g_GameClient.m_pSounds->PlayAt(CSounds::CHN_WORLD, ev->m_SoundID, 1.0f, vec2(ev->m_X, ev->m_Y)); } } } @@ -862,6 +868,17 @@ } } } + // sort player infos by team + int Teams[3] = { TEAM_RED, TEAM_BLUE, TEAM_SPECTATORS }; + int Index = 0; + for(int Team = 0; Team < 3; ++Team) + { + for(int i = 0; i < MAX_CLIENTS && Index < MAX_CLIENTS; ++i) + { + if(m_Snap.m_paPlayerInfos[i] && m_Snap.m_paPlayerInfos[i]->m_Team == Teams[Team]) + m_Snap.m_paInfoByTeam[Index++] = m_Snap.m_paPlayerInfos[i]; + } + } CTuningParams StandardTuning; CServerInfo CurrentServerInfo; @@ -876,6 +893,15 @@ m_ServerMode = SERVERMODE_PUREMOD; } + // add tuning to demo + if(DemoRecorder()->IsRecording() && mem_comp(&StandardTuning, &m_Tuning, sizeof(CTuningParams)) != 0) + { + CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); + int *pParams = (int *)&m_Tuning; + for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) + Msg.AddInt(pParams[i]); + Client()->SendMsg(&Msg, MSGFLAG_RECORD|MSGFLAG_NOSEND); + } } void CGameClient::OnPredict() diff -Nru teeworlds-0.6.1+dfsg/src/game/client/gameclient.h teeworlds-0.6.2+dfsg/src/game/client/gameclient.h --- teeworlds-0.6.1+dfsg/src/game/client/gameclient.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/gameclient.h 2013-05-01 11:47:39.000000000 +0000 @@ -125,6 +125,7 @@ const CNetObj_PlayerInfo *m_paPlayerInfos[MAX_CLIENTS]; const CNetObj_PlayerInfo *m_paInfoByScore[MAX_CLIENTS]; + const CNetObj_PlayerInfo *m_paInfoByTeam[MAX_CLIENTS]; int m_LocalClientID; int m_NumPlayers; @@ -241,6 +242,8 @@ class CVoting *m_pVoting; class CScoreboard *m_pScoreboard; class CItems *m_pItems; + class CMapLayers *m_pMapLayersBackGround; + class CMapLayers *m_pMapLayersForeGround; }; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/lineinput.cpp teeworlds-0.6.2+dfsg/src/game/client/lineinput.cpp --- teeworlds-0.6.1+dfsg/src/game/client/lineinput.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/lineinput.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -13,6 +13,7 @@ mem_zero(m_Str, sizeof(m_Str)); m_Len = 0; m_CursorPos = 0; + m_NumChars = 0; } void CLineInput::Set(const char *pString) @@ -20,10 +21,18 @@ str_copy(m_Str, pString, sizeof(m_Str)); m_Len = str_length(m_Str); m_CursorPos = m_Len; + m_NumChars = 0; + int Offset = 0; + while(pString[Offset]) + { + Offset = str_utf8_forward(pString, Offset); + ++m_NumChars; + } } -bool CLineInput::Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int *pStrLenPtr, int *pCursorPosPtr) +bool CLineInput::Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr) { + int NumChars = *pNumCharsPtr; int CursorPos = *pCursorPosPtr; int Len = *pStrLenPtr; bool Changes = false; @@ -40,13 +49,15 @@ char Tmp[8]; int CharSize = str_utf8_encode(Tmp, Code); - if (Len < StrMaxSize - CharSize && CursorPos < StrMaxSize - CharSize) + if (Len < StrMaxSize - CharSize && CursorPos < StrMaxSize - CharSize && NumChars < StrMaxChars) { mem_move(pStr + CursorPos + CharSize, pStr + CursorPos, Len-CursorPos+1); // +1 == null term for(int i = 0; i < CharSize; i++) pStr[CursorPos+i] = Tmp[i]; CursorPos += CharSize; Len += CharSize; + if(CharSize > 0) + ++NumChars; Changes = true; } } @@ -60,6 +71,8 @@ mem_move(pStr+NewCursorPos, pStr+CursorPos, Len - NewCursorPos - CharSize + 1); // +1 == null term CursorPos = NewCursorPos; Len -= CharSize; + if(CharSize > 0) + --NumChars; Changes = true; } else if (k == KEY_DELETE && CursorPos < Len) @@ -68,6 +81,8 @@ int CharSize = p-CursorPos; mem_move(pStr + CursorPos, pStr + CursorPos + CharSize, Len - CursorPos - CharSize + 1); // +1 == null term Len -= CharSize; + if(CharSize > 0) + --NumChars; Changes = true; } else if (k == KEY_LEFT && CursorPos > 0) @@ -80,6 +95,7 @@ CursorPos = Len; } + *pNumCharsPtr = NumChars; *pCursorPosPtr = CursorPos; *pStrLenPtr = Len; @@ -88,5 +104,5 @@ void CLineInput::ProcessInput(IInput::CEvent e) { - Manipulate(e, m_Str, sizeof(m_Str), &m_Len, &m_CursorPos); + Manipulate(e, m_Str, MAX_SIZE, MAX_CHARS, &m_Len, &m_CursorPos, &m_NumChars); } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/lineinput.h teeworlds-0.6.2+dfsg/src/game/client/lineinput.h --- teeworlds-0.6.1+dfsg/src/game/client/lineinput.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/lineinput.h 2013-05-01 11:47:39.000000000 +0000 @@ -8,11 +8,17 @@ // line input helter class CLineInput { - char m_Str[256]; + enum + { + MAX_SIZE=512, + MAX_CHARS=MAX_SIZE/4, + }; + char m_Str[MAX_SIZE]; int m_Len; int m_CursorPos; + int m_NumChars; public: - static bool Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int *pStrLenPtr, int *pCursorPosPtr); + static bool Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr); class CCallback { diff -Nru teeworlds-0.6.1+dfsg/src/game/client/render.cpp teeworlds-0.6.2+dfsg/src/game/client/render.cpp --- teeworlds-0.6.1+dfsg/src/game/client/render.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/render.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -75,7 +75,7 @@ void CRenderTools::SelectSprite(int Id, int Flags, int sx, int sy) { - if(Id < 0 || Id > g_pData->m_NumSprites) + if(Id < 0 || Id >= g_pData->m_NumSprites) return; SelectSprite(&g_pData->m_aSprites[Id], Flags, sx, sy); } @@ -314,7 +314,7 @@ CTile *pTiles = (CTile *)pLayers->Map()->GetData(pTmap->m_Data); for(int y = 0; y < pTmap->m_Height; y++) { - for(int x = 1; x < pTmap->m_Width; x++) + for(int x = 1; x < pTmap->m_Width;) { int sx; for(sx = 1; x+sx < pTmap->m_Width && sx < 255; sx++) @@ -324,6 +324,7 @@ } pTiles[y*pTmap->m_Width+x].m_Skip = sx-1; + x += sx; } } } diff -Nru teeworlds-0.6.1+dfsg/src/game/client/render_map.cpp teeworlds-0.6.2+dfsg/src/game/client/render_map.cpp --- teeworlds-0.6.1+dfsg/src/game/client/render_map.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/render_map.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -99,9 +99,10 @@ } bool Opaque = false; + /* TODO: Analyze quadtexture if(a < 0.01f || (q->m_aColors[0].a < 0.01f && q->m_aColors[1].a < 0.01f && q->m_aColors[2].a < 0.01f && q->m_aColors[3].a < 0.01f)) Opaque = true; - + */ if(Opaque && !(RenderFlags&LAYERRENDERFLAG_OPAQUE)) continue; if(!Opaque && !(RenderFlags&LAYERRENDERFLAG_TRANSPARENT)) @@ -236,7 +237,7 @@ unsigned char Flags = pTiles[c].m_Flags; bool Render = false; - if(Flags&TILEFLAG_OPAQUE) + if(Flags&TILEFLAG_OPAQUE && Color.a*a > 254.0f/255.0f) { if(RenderFlags&LAYERRENDERFLAG_OPAQUE) Render = true; diff -Nru teeworlds-0.6.1+dfsg/src/game/client/ui.cpp teeworlds-0.6.2+dfsg/src/game/client/ui.cpp --- teeworlds-0.6.1+dfsg/src/game/client/ui.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/ui.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -74,6 +74,11 @@ return &m_Screen; } +float CUI::PixelSize() +{ + return Screen()->w/Graphics()->ScreenWidth(); +} + void CUI::SetScale(float s) { g_Config.m_UiScale = (int)(s*100.0f); diff -Nru teeworlds-0.6.1+dfsg/src/game/client/ui.h teeworlds-0.6.2+dfsg/src/game/client/ui.h --- teeworlds-0.6.1+dfsg/src/game/client/ui.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/client/ui.h 2013-05-01 11:47:39.000000000 +0000 @@ -82,6 +82,7 @@ void ConvertMouseMove(float *x, float *y); CUIRect *Screen(); + float PixelSize(); void ClipEnable(const CUIRect *pRect); void ClipDisable(); diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/auto_map.cpp teeworlds-0.6.2+dfsg/src/game/editor/auto_map.cpp --- teeworlds-0.6.1+dfsg/src/game/editor/auto_map.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/auto_map.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -20,15 +20,15 @@ IOHANDLE RulesFile = m_pEditor->Storage()->OpenFile(aPath, IOFLAG_READ, IStorage::TYPE_ALL); if(!RulesFile) return; - + CLineReader LineReader; LineReader.Init(RulesFile); - + CConfiguration *pCurrentConf = 0; CIndexRule *pCurrentIndex = 0; - + char aBuf[256]; - + // read each line while(char *pLine = LineReader.Get()) { @@ -40,11 +40,11 @@ { // new configuration, get the name pLine++; - + CConfiguration NewConf; int ID = m_lConfigs.add(NewConf); pCurrentConf = &m_lConfigs[ID]; - + str_copy(pCurrentConf->m_aName, pLine, str_length(pLine)); } else @@ -54,15 +54,15 @@ // new index int ID = 0; char aFlip[128] = ""; - + sscanf(pLine, "Index %d %127s", &ID, aFlip); - + CIndexRule NewIndexRule; NewIndexRule.m_ID = ID; NewIndexRule.m_Flag = 0; NewIndexRule.m_RandomValue = 0; NewIndexRule.m_BaseTile = false; - + if(str_length(aFlip) > 0) { if(!str_comp(aFlip, "XFLIP")) @@ -70,7 +70,7 @@ else if(!str_comp(aFlip, "YFLIP")) NewIndexRule.m_Flag = TILEFLAG_HFLIP; } - + // add the index rule object and make it current int ArrayID = pCurrentConf->m_aIndexRules.add(NewIndexRule); pCurrentIndex = &pCurrentConf->m_aIndexRules[ArrayID]; @@ -85,9 +85,9 @@ char aValue[128]; int Value = CPosRule::EMPTY; bool IndexValue = false; - + sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue); - + if(!str_comp(aValue, "FULL")) Value = CPosRule::FULL; else if(!str_comp_num(aValue, "INDEX", 5)) @@ -106,12 +106,12 @@ } } } - + io_close(RulesFile); - + str_format(aBuf, sizeof(aBuf),"loaded %s", aPath); m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor", aBuf); - + m_FileLoaded = true; } @@ -127,14 +127,14 @@ { if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= m_lConfigs.size()) return; - + CConfiguration *pConf = &m_lConfigs[ConfigID]; - + if(!pConf->m_aIndexRules.size()) return; - + int BaseTile = 1; - + // find base tile if there is one for(int i = 0; i < pConf->m_aIndexRules.size(); ++i) { @@ -144,7 +144,7 @@ break; } } - + // auto map ! int MaxIndex = pLayer->m_Width*pLayer->m_Height; for(int y = 0; y < pLayer->m_Height; y++) @@ -159,7 +159,7 @@ if(y == 0 || y == pLayer->m_Height-1 || x == 0 || x == pLayer->m_Width-1) continue; - + for(int i = 0; i < pConf->m_aIndexRules.size(); ++i) { if(pConf->m_aIndexRules[i].m_BaseTile) @@ -170,7 +170,7 @@ { CPosRule *pRule = &pConf->m_aIndexRules[i].m_aRules[j]; int CheckIndex = (y+pRule->m_Y)*pLayer->m_Width+(x+pRule->m_X); - + if(CheckIndex < 0 || CheckIndex >= MaxIndex) RespectRules = false; else @@ -184,15 +184,15 @@ { if(pLayer->m_pTiles[CheckIndex].m_Index > 0 && pRule->m_Value == CPosRule::EMPTY) RespectRules = false; - + if(pLayer->m_pTiles[CheckIndex].m_Index == 0 && pRule->m_Value == CPosRule::FULL) RespectRules = false; } } } - + if(RespectRules && - (pConf->m_aIndexRules[i].m_RandomValue <= 1 || (int)((float)rand() / ((float)RAND_MAX + 1) * pConf->m_aIndexRules[i].m_RandomValue) == 1)) + (pConf->m_aIndexRules[i].m_RandomValue <= 1 || (int)((float)rand() / ((float)RAND_MAX + 1) * pConf->m_aIndexRules[i].m_RandomValue) == 1)) { pTile->m_Index = pConf->m_aIndexRules[i].m_ID; pTile->m_Flags = pConf->m_aIndexRules[i].m_Flag; diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/auto_map.h teeworlds-0.6.2+dfsg/src/game/editor/auto_map.h --- teeworlds-0.6.1+dfsg/src/game/editor/auto_map.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/auto_map.h 2013-05-01 11:47:39.000000000 +0000 @@ -11,7 +11,7 @@ int m_Y; int m_Value; bool m_IndexValue; - + enum { EMPTY=0, @@ -33,16 +33,16 @@ array m_aIndexRules; char m_aName[128]; }; - + public: CAutoMapper(class CEditor *pEditor); - + void Load(const char* pTileName); void Proceed(class CLayerTiles *pLayer, int ConfigID); int ConfigNamesNum() { return m_lConfigs.size(); } const char* GetConfigName(int Index); - + const bool IsLoaded() { return m_FileLoaded; } private: array m_lConfigs; diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/editor.cpp teeworlds-0.6.2+dfsg/src/game/editor/editor.cpp --- teeworlds-0.6.1+dfsg/src/game/editor/editor.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/editor.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -37,6 +37,11 @@ CEditorImage::~CEditorImage() { m_pEditor->Graphics()->UnloadTexture(m_TexID); + if(m_pData) + { + mem_free(m_pData); + m_pData = 0; + } } CLayerGroup::CLayerGroup() @@ -164,7 +169,7 @@ int tw = m_Width/16; // tilesizes int th = m_Height/16; if ( tw == th ) - { + { unsigned char *pPixelData = (unsigned char *)m_pData; int TileID = 0; @@ -214,7 +219,6 @@ // copied from gc_menu.cpp, should be more generalized //extern int ui_do_edit_box(void *id, const CUIRect *rect, char *str, int str_size, float font_size, bool hidden=false); - int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners) { int Inside = UI()->MouseInside(pRect); @@ -228,6 +232,7 @@ if(UI()->LastActiveItem() == pID) { + m_EditBoxActive = 2; int Len = str_length(pStr); if(Len == 0) s_AtIndex = 0; @@ -272,7 +277,8 @@ for(int i = 0; i < Input()->NumEvents(); i++) { Len = str_length(pStr); - ReturnValue |= CLineInput::Manipulate(Input()->GetEvent(i), pStr, StrSize, &Len, &s_AtIndex); + int NumChars = Len; + ReturnValue |= CLineInput::Manipulate(Input()->GetEvent(i), pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars); } } @@ -381,8 +387,8 @@ Handle.y += (pRect->h-Handle.h)*Current; // logic - float Ret = Current; - int Inside = UI()->MouseInside(&Handle); + float Ret = Current; + int Inside = UI()->MouseInside(&Handle); if(UI()->ActiveItem() == pID) { @@ -423,7 +429,7 @@ Slider.Margin(5.0f, &Slider); RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f)*ButtonColorMul(pID), CUI::CORNER_ALL, 2.5f); - return Ret; + return Ret; } vec4 CEditor::GetButtonColor(const void *pID, int Checked) @@ -490,7 +496,7 @@ int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { CUIRect r = *pRect; - RenderTools()->DrawUIRect(&r, vec4(0.5f, 0.5f, 0.5f, 1.0f), CUI::CORNER_T, 3.0f); + RenderTools()->DrawUIRect(&r, vec4(0.5f, 0.5f, 0.5f, 1.0f), CUI::CORNER_T, 3.0f); r = *pRect; r.VMargin(5.0f, &r); @@ -515,18 +521,18 @@ int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), CUI::CORNER_T, 5.0f); - CUIRect NewRect = *pRect; - NewRect.y += NewRect.h/2.0f-7.0f; - UI()->DoLabel(&NewRect, pText, 10, 0, -1); + CUIRect NewRect = *pRect; + NewRect.y += NewRect.h/2.0f-7.0f; + UI()->DoLabel(&NewRect, pText, 10, 0, -1); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize) { RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, Checked), Corners, 3.0f); - CUIRect NewRect = *pRect; - NewRect.HMargin(NewRect.h/2.0f-FontSize/2.0f-1.0f, &NewRect); - UI()->DoLabel(&NewRect, pText, FontSize, 0, -1); + CUIRect NewRect = *pRect; + NewRect.HMargin(NewRect.h/2.0f-FontSize/2.0f-1.0f, &NewRect); + UI()->DoLabel(&NewRect, pText, FontSize, 0, -1); return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } @@ -550,7 +556,7 @@ return; float aGroupPoints[4]; - pGroup->Mapping(aGroupPoints); + pGroup->Mapping(aGroupPoints); float w = UI()->Screen()->w; float h = UI()->Screen()->h; @@ -562,7 +568,7 @@ int XGridOffset = XOffset % m_GridFactor; int YGridOffset = YOffset % m_GridFactor; - Graphics()->TextureSet(-1); + Graphics()->TextureSet(-1); Graphics()->LinesBegin(); for(int i = 0; i < (int)w; i++) @@ -601,9 +607,9 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip) { - // logic - static float s_Value; - int Inside = UI()->MouseInside(pRect); + // logic + static float s_Value; + int Inside = UI()->MouseInside(pRect); if(UI()->ActiveItem() == pID) { @@ -652,9 +658,9 @@ char aBuf[128]; str_format(aBuf, sizeof(aBuf),"%s %d", pLabel, Current); RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, 0), CUI::CORNER_ALL, 5.0f); - pRect->y += pRect->h/2.0f-7.0f; - UI()->DoLabel(pRect, aBuf, 10, 0, -1); - + pRect->y += pRect->h/2.0f-7.0f; + UI()->DoLabel(pRect, aBuf, 10, 0, -1); + return Current; } @@ -713,7 +719,7 @@ pEditor->m_aFileName[0] = 0; else pEditor->SortImages(); - + pEditor->m_Dialog = DIALOG_NONE; } void CEditor::CallbackSaveMap(const char *pFileName, int StorageType, void *pUser) @@ -734,7 +740,7 @@ pEditor->m_ValidSaveFilename = StorageType == IStorage::TYPE_SAVE && pEditor->m_pFileDialogPath == pEditor->m_aFileDialogCurrentFolder; pEditor->m_Map.m_Modified = false; } - + pEditor->m_Dialog = DIALOG_NONE; } @@ -742,32 +748,38 @@ { CUIRect TB_Top, TB_Bottom; CUIRect Button; - + ToolBar.HSplitTop(ToolBar.h/2.0f, &TB_Top, &TB_Bottom); - - TB_Top.HSplitBottom(2.5f, &TB_Top, 0); - TB_Bottom.HSplitTop(2.5f, 0, &TB_Bottom); + + TB_Top.HSplitBottom(2.5f, &TB_Top, 0); + TB_Bottom.HSplitTop(2.5f, 0, &TB_Bottom); // ctrl+o to open - if(Input()->KeyDown('o') && (Input()->KeyPressed(KEY_LCTRL) || Input()->KeyPressed(KEY_RCTRL))) + if(Input()->KeyDown('o') && (Input()->KeyPressed(KEY_LCTRL) || Input()->KeyPressed(KEY_RCTRL)) && m_Dialog == DIALOG_NONE) { if(HasUnsavedData()) { - m_PopupEventType = POPEVENT_LOAD; - m_PopupEventActivated = true; + if(!m_PopupEventWasActivated) + { + m_PopupEventType = POPEVENT_LOAD; + m_PopupEventActivated = true; + } } else InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_MAP, "Load map", "Load", "maps", "", CallbackOpenMap, this); } // ctrl+s to save - if(Input()->KeyDown('s') && (Input()->KeyPressed(KEY_LCTRL) || Input()->KeyPressed(KEY_RCTRL))) + if(Input()->KeyDown('s') && (Input()->KeyPressed(KEY_LCTRL) || Input()->KeyPressed(KEY_RCTRL)) && m_Dialog == DIALOG_NONE) { - if(m_aFileName[0] && m_ValidSaveFilename) + if(m_aFileName[0] && m_ValidSaveFilename) { - str_copy(m_aFileSaveName, m_aFileName, sizeof(m_aFileSaveName)); - m_PopupEventType = POPEVENT_SAVE; - m_PopupEventActivated = true; + if(!m_PopupEventWasActivated) + { + str_copy(m_aFileSaveName, m_aFileName, sizeof(m_aFileSaveName)); + m_PopupEventType = POPEVENT_SAVE; + m_PopupEventActivated = true; + } } else InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_MAP, "Save map", "Save", "maps", "", CallbackSaveMap, this); @@ -814,6 +826,7 @@ (Input()->KeyDown('i') && (Input()->KeyPressed(KEY_LCTRL) || Input()->KeyPressed(KEY_RCTRL)))) { m_ShowTileInfo = !m_ShowTileInfo; + m_ShowEnvelopePreview = 0; } TB_Top.VSplitLeft(15.0f, 0, &TB_Top); @@ -821,12 +834,12 @@ // zoom group TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_ZoomOutButton = 0; - if(DoButton_Ex(&s_ZoomOutButton, "ZO", 0, &Button, 0, "[NumPad-] Zoom out", CUI::CORNER_L) || Input()->KeyDown(KEY_KP_MINUS)) + if(DoButton_Ex(&s_ZoomOutButton, "ZO", 0, &Button, 0, "[NumPad-] Zoom out", CUI::CORNER_L)) m_ZoomLevel += 50; TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_ZoomNormalButton = 0; - if(DoButton_Ex(&s_ZoomNormalButton, "1:1", 0, &Button, 0, "[NumPad*] Zoom to normal and remove editor offset", 0) || Input()->KeyDown(KEY_KP_MULTIPLY)) + if(DoButton_Ex(&s_ZoomNormalButton, "1:1", 0, &Button, 0, "[NumPad*] Zoom to normal and remove editor offset", 0)) { m_EditorOffsetX = 0; m_EditorOffsetY = 0; @@ -835,7 +848,7 @@ TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_ZoomInButton = 0; - if(DoButton_Ex(&s_ZoomInButton, "ZI", 0, &Button, 0, "[NumPad+] Zoom in", CUI::CORNER_R) || Input()->KeyDown(KEY_KP_PLUS)) + if(DoButton_Ex(&s_ZoomInButton, "ZI", 0, &Button, 0, "[NumPad+] Zoom in", CUI::CORNER_R)) m_ZoomLevel -= 50; TB_Top.VSplitLeft(10.0f, 0, &TB_Top); @@ -859,8 +872,6 @@ m_AnimateSpeed -= 0.5f; } - m_WorldZoom = m_ZoomLevel/100.0f; - TB_Top.VSplitLeft(10.0f, &Button, &TB_Top); @@ -947,17 +958,17 @@ } } } - + // tile manipulation { TB_Bottom.VSplitLeft(40.0f, &Button, &TB_Bottom); static int s_BorderBut = 0; CLayerTiles *pT = (CLayerTiles *)GetSelectedLayerType(0, LAYERTYPE_TILES); - + if(DoButton_Editor(&s_BorderBut, "Border", pT?0:-1, &Button, 0, "Adds border tiles")) { if(pT) - DoMapBorder(); + DoMapBorder(); } } @@ -966,7 +977,7 @@ // refocus button TB_Bottom.VSplitLeft(50.0f, &Button, &TB_Bottom); static int s_RefocusButton = 0; - if(DoButton_Editor(&s_RefocusButton, "Refocus", m_WorldOffsetX&&m_WorldOffsetY?0:-1, &Button, 0, "[HOME] Restore map focus") || Input()->KeyDown(KEY_HOME)) + if(DoButton_Editor(&s_RefocusButton, "Refocus", m_WorldOffsetX&&m_WorldOffsetY?0:-1, &Button, 0, "[HOME] Restore map focus") || (m_EditBoxActive == 0 && Input()->KeyDown(KEY_HOME))) { m_WorldOffsetX = 0; m_WorldOffsetY = 0; @@ -1008,7 +1019,7 @@ } } -static void Rotate(CPoint *pCenter, CPoint *pPoint, float Rotation) +static void Rotate(const CPoint *pCenter, CPoint *pPoint, float Rotation) { int x = pPoint->x - pCenter->x; int y = pPoint->y - pCenter->y; @@ -1046,6 +1057,12 @@ if(dx*dx+dy*dy < 50) UI()->SetHotItem(pID); + bool IgnoreGrid; + if(Input()->KeyPressed(KEY_LALT) || Input()->KeyPressed(KEY_RALT)) + IgnoreGrid = true; + else + IgnoreGrid = false; + // draw selection background if(m_SelectedQuad == Index) { @@ -1056,58 +1073,82 @@ if(UI()->ActiveItem() == pID) { - // check if we only should move pivot - if(s_Operation == OP_MOVE_PIVOT) + if(m_MouseDeltaWx*m_MouseDeltaWx+m_MouseDeltaWy*m_MouseDeltaWy > 0.5f) { - q->m_aPoints[4].x += f2fx(wx-s_LastWx); - q->m_aPoints[4].y += f2fx(wy-s_LastWy); - } - else if(s_Operation == OP_MOVE_ALL) - { - // move all points including pivot - if(m_GridActive) + // check if we only should move pivot + if(s_Operation == OP_MOVE_PIVOT) { - int LineDistance = GetLineDistance(); + if(m_GridActive && !IgnoreGrid) + { + int LineDistance = GetLineDistance(); - float x = 0.0f; - float y = 0.0f; - if(wx >= 0) - x = (int)((wx+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); - else - x = (int)((wx-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); - if(wy >= 0) - y = (int)((wy+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + float x = 0.0f; + float y = 0.0f; + if(wx >= 0) + x = (int)((wx+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + else + x = (int)((wx-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + if(wy >= 0) + y = (int)((wy+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + else + y = (int)((wy-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + + q->m_aPoints[4].x = f2fx(x); + q->m_aPoints[4].y = f2fx(y); + } else - y = (int)((wy-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); - - int OldX = q->m_aPoints[4].x; - int OldY = q->m_aPoints[4].y; - q->m_aPoints[4].x = f2fx(x); - q->m_aPoints[4].y = f2fx(y); - int DiffX = q->m_aPoints[4].x - OldX; - int DiffY = q->m_aPoints[4].y - OldY; - - for(int v = 0; v < 4; v++) { - q->m_aPoints[v].x += DiffX; - q->m_aPoints[v].y += DiffY; + q->m_aPoints[4].x += f2fx(wx-s_LastWx); + q->m_aPoints[4].y += f2fx(wy-s_LastWy); } } - else + else if(s_Operation == OP_MOVE_ALL) { - for(int v = 0; v < 5; v++) + // move all points including pivot + if(m_GridActive && !IgnoreGrid) { - q->m_aPoints[v].x += f2fx(wx-s_LastWx); - q->m_aPoints[v].y += f2fx(wy-s_LastWy); + int LineDistance = GetLineDistance(); + + float x = 0.0f; + float y = 0.0f; + if(wx >= 0) + x = (int)((wx+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + else + x = (int)((wx-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + if(wy >= 0) + y = (int)((wy+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + else + y = (int)((wy-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + + int OldX = q->m_aPoints[4].x; + int OldY = q->m_aPoints[4].y; + q->m_aPoints[4].x = f2fx(x); + q->m_aPoints[4].y = f2fx(y); + int DiffX = q->m_aPoints[4].x - OldX; + int DiffY = q->m_aPoints[4].y - OldY; + + for(int v = 0; v < 4; v++) + { + q->m_aPoints[v].x += DiffX; + q->m_aPoints[v].y += DiffY; + } + } + else + { + for(int v = 0; v < 5; v++) + { + q->m_aPoints[v].x += f2fx(wx-s_LastWx); + q->m_aPoints[v].y += f2fx(wy-s_LastWy); + } } } - } - else if(s_Operation == OP_ROTATE) - { - for(int v = 0; v < 4; v++) + else if(s_Operation == OP_ROTATE) { - q->m_aPoints[v] = s_RotatePoints[v]; - Rotate(&q->m_aPoints[4], &q->m_aPoints[v], s_RotateAngle); + for(int v = 0; v < 4; v++) + { + q->m_aPoints[v] = s_RotatePoints[v]; + Rotate(&q->m_aPoints[4], &q->m_aPoints[v], s_RotateAngle); + } } } @@ -1143,7 +1184,7 @@ ms_pUiGotContext = pID; Graphics()->SetColor(1,1,1,1); - m_pTooltip = "Left mouse button to move. Hold shift to move pivot. Hold ctrl to rotate."; + m_pTooltip = "Left mouse button to move. Hold shift to move pivot. Hold ctrl to rotate. Hold alt to ignore grid."; if(UI()->MouseButton(0)) { @@ -1163,6 +1204,8 @@ s_Operation = OP_MOVE_ALL; UI()->SetActiveItem(pID); + if(m_SelectedQuad != Index) + m_SelectedPoints = 0; m_SelectedQuad = Index; s_LastWx = wx; s_LastWy = wy; @@ -1170,6 +1213,8 @@ if(UI()->MouseButton(1)) { + if(m_SelectedQuad != Index) + m_SelectedPoints = 0; m_SelectedQuad = Index; s_Operation = OP_CONTEXT_MENU; UI()->SetActiveItem(pID); @@ -1216,6 +1261,12 @@ static bool s_Moved; static int s_Operation = OP_NONE; + bool IgnoreGrid; + if(Input()->KeyPressed(KEY_LALT) || Input()->KeyPressed(KEY_RALT)) + IgnoreGrid = true; + else + IgnoreGrid = false; + if(UI()->ActiveItem() == pID) { float dx = m_MouseDeltaWx; @@ -1230,7 +1281,7 @@ { if(s_Operation == OP_MOVEPOINT) { - if(m_GridActive) + if(m_GridActive && !IgnoreGrid) { for(int m = 0; m < 4; m++) if(m_SelectedPoints&(1<m_aTexcoords[m].x += f2fx(dx*0.001f); pQuad->m_aTexcoords[(m+2)%4].x += f2fx(dx*0.001f); - + pQuad->m_aTexcoords[m].y += f2fx(dy*0.001f); pQuad->m_aTexcoords[m^1].y += f2fx(dy*0.001f); } @@ -1311,7 +1362,7 @@ ms_pUiGotContext = pID; Graphics()->SetColor(1,1,1,1); - m_pTooltip = "Left mouse button to move. Hold shift to move the texture."; + m_pTooltip = "Left mouse button to move. Hold shift to move the texture. Hold alt to ignore grid."; if(UI()->MouseButton(0)) { @@ -1358,6 +1409,245 @@ Graphics()->QuadsDraw(&QuadItem, 1); } +void CEditor::DoQuadEnvelopes(const array &lQuads, int TexID) +{ + int Num = lQuads.size(); + CEnvelope **apEnvelope = new CEnvelope*[Num]; + mem_zero(apEnvelope, sizeof(CEnvelope*)*Num); + for(int i = 0; i < Num; i++) + { + if((m_ShowEnvelopePreview == 1 && lQuads[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2) + if(lQuads[i].m_PosEnv >= 0 && lQuads[i].m_PosEnv < m_Map.m_lEnvelopes.size()) + apEnvelope[i] = m_Map.m_lEnvelopes[lQuads[i].m_PosEnv]; + } + + //Draw Lines + Graphics()->TextureSet(-1); + Graphics()->LinesBegin(); + Graphics()->SetColor(80.0f/255, 150.0f/255, 230.f/255, 0.5f); + for(int j = 0; j < Num; j++) + { + if(!apEnvelope[j]) + continue; + + //QuadParams + const CPoint *pPoints = lQuads[j].m_aPoints; + for(int i = 0; i < apEnvelope[j]->m_lPoints.size()-1; i++) + { + float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]); + float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]); + vec2 Pos0 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); + + OffsetX = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[0]); + OffsetY = fx2f(apEnvelope[j]->m_lPoints[i+1].m_aValues[1]); + vec2 Pos1 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); + + IGraphics::CLineItem Line = IGraphics::CLineItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y); + Graphics()->LinesDraw(&Line, 1); + } + } + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + Graphics()->LinesEnd(); + + //Draw Quads + Graphics()->TextureSet(TexID); + Graphics()->QuadsBegin(); + + for(int j = 0; j < Num; j++) + { + if(!apEnvelope[j]) + continue; + + //QuadParams + const CPoint *pPoints = lQuads[j].m_aPoints; + + for(int i = 0; i < apEnvelope[j]->m_lPoints.size(); i++) + { + //Calc Env Position + float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]); + float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]); + float Rot = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[2])/360.0f*pi*2; + + //Set Colours + float Alpha = (m_SelectedQuadEnvelope == lQuads[j].m_PosEnv && m_SelectedEnvelopePoint == i) ? 0.65f : 0.35f; + IGraphics::CColorVertex aArray[4] = { + IGraphics::CColorVertex(0, lQuads[j].m_aColors[0].r, lQuads[j].m_aColors[0].g, lQuads[j].m_aColors[0].b, Alpha), + IGraphics::CColorVertex(1, lQuads[j].m_aColors[1].r, lQuads[j].m_aColors[1].g, lQuads[j].m_aColors[1].b, Alpha), + IGraphics::CColorVertex(2, lQuads[j].m_aColors[2].r, lQuads[j].m_aColors[2].g, lQuads[j].m_aColors[2].b, Alpha), + IGraphics::CColorVertex(3, lQuads[j].m_aColors[3].r, lQuads[j].m_aColors[3].g, lQuads[j].m_aColors[3].b, Alpha)}; + Graphics()->SetColorVertex(aArray, 4); + + //Rotation + if(Rot != 0) + { + static CPoint aRotated[4]; + aRotated[0] = lQuads[j].m_aPoints[0]; + aRotated[1] = lQuads[j].m_aPoints[1]; + aRotated[2] = lQuads[j].m_aPoints[2]; + aRotated[3] = lQuads[j].m_aPoints[3]; + pPoints = aRotated; + + Rotate(&lQuads[j].m_aPoints[4], &aRotated[0], Rot); + Rotate(&lQuads[j].m_aPoints[4], &aRotated[1], Rot); + Rotate(&lQuads[j].m_aPoints[4], &aRotated[2], Rot); + Rotate(&lQuads[j].m_aPoints[4], &aRotated[3], Rot); + } + + //Set Texture Coords + Graphics()->QuadsSetSubsetFree( + fx2f(lQuads[j].m_aTexcoords[0].x), fx2f(lQuads[j].m_aTexcoords[0].y), + fx2f(lQuads[j].m_aTexcoords[1].x), fx2f(lQuads[j].m_aTexcoords[1].y), + fx2f(lQuads[j].m_aTexcoords[2].x), fx2f(lQuads[j].m_aTexcoords[2].y), + fx2f(lQuads[j].m_aTexcoords[3].x), fx2f(lQuads[j].m_aTexcoords[3].y) + ); + + //Set Quad Coords & Draw + IGraphics::CFreeformItem Freeform( + fx2f(pPoints[0].x)+OffsetX, fx2f(pPoints[0].y)+OffsetY, + fx2f(pPoints[1].x)+OffsetX, fx2f(pPoints[1].y)+OffsetY, + fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY, + fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY); + Graphics()->QuadsDrawFreeform(&Freeform, 1); + } + } + Graphics()->QuadsEnd(); + Graphics()->TextureSet(-1); + Graphics()->QuadsBegin(); + + // Draw QuadPoints + for(int j = 0; j < Num; j++) + { + if(!apEnvelope[j]) + continue; + + //QuadParams + for(int i = 0; i < apEnvelope[j]->m_lPoints.size()-1; i++) + DoQuadEnvPoint(&lQuads[j], j, i); + } + Graphics()->QuadsEnd(); + delete[] apEnvelope; +} + +void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex) +{ + enum + { + OP_NONE=0, + OP_MOVE, + OP_ROTATE, + }; + + // some basic values + static float s_LastWx; + static float s_LastWy; + static int s_Operation = OP_NONE; + float wx = UI()->MouseWorldX(); + float wy = UI()->MouseWorldY(); + CEnvelope *pEnvelope = m_Map.m_lEnvelopes[pQuad->m_PosEnv]; + void *pID = &pEnvelope->m_lPoints[PIndex]; + static int s_ActQIndex = -1; + + // get pivot + float CenterX = fx2f(pQuad->m_aPoints[4].x)+fx2f(pEnvelope->m_lPoints[PIndex].m_aValues[0]); + float CenterY = fx2f(pQuad->m_aPoints[4].y)+fx2f(pEnvelope->m_lPoints[PIndex].m_aValues[1]); + + float dx = (CenterX - wx)/m_WorldZoom; + float dy = (CenterY - wy)/m_WorldZoom; + if(dx*dx+dy*dy < 50.0f && UI()->ActiveItem() == 0) + { + UI()->SetHotItem(pID); + s_ActQIndex = QIndex; + } + + bool IgnoreGrid; + if(Input()->KeyPressed(KEY_LALT) || Input()->KeyPressed(KEY_RALT)) + IgnoreGrid = true; + else + IgnoreGrid = false; + + if(UI()->ActiveItem() == pID && s_ActQIndex == QIndex) + { + if(s_Operation == OP_MOVE) + { + if(m_GridActive && !IgnoreGrid) + { + int LineDistance = GetLineDistance(); + + float x = 0.0f; + float y = 0.0f; + if(wx >= 0) + x = (int)((wx+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + else + x = (int)((wx-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + if(wy >= 0) + y = (int)((wy+(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + else + y = (int)((wy-(LineDistance/2)*m_GridFactor)/(LineDistance*m_GridFactor)) * (LineDistance*m_GridFactor); + + pEnvelope->m_lPoints[PIndex].m_aValues[0] = f2fx(x); + pEnvelope->m_lPoints[PIndex].m_aValues[1] = f2fx(y); + } + else + { + pEnvelope->m_lPoints[PIndex].m_aValues[0] += f2fx(wx-s_LastWx); + pEnvelope->m_lPoints[PIndex].m_aValues[1] += f2fx(wy-s_LastWy); + } + } + else if(s_Operation == OP_ROTATE) + pEnvelope->m_lPoints[PIndex].m_aValues[2] += 10*m_MouseDeltaX; + + s_LastWx = wx; + s_LastWy = wy; + + if(!UI()->MouseButton(0)) + { + m_LockMouse = false; + s_Operation = OP_NONE; + UI()->SetActiveItem(0); + } + + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + } + else if(UI()->HotItem() == pID && s_ActQIndex == QIndex) + { + ms_pUiGotContext = pID; + + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + m_pTooltip = "Left mouse button to move. Hold ctrl to rotate. Hold alt to ignore grid."; + + if(UI()->MouseButton(0)) + { + if(Input()->KeyPressed(KEY_LCTRL) || Input()->KeyPressed(KEY_RCTRL)) + { + m_LockMouse = true; + s_Operation = OP_ROTATE; + } + else + s_Operation = OP_MOVE; + + m_SelectedEnvelopePoint = PIndex; + m_SelectedQuadEnvelope = pQuad->m_PosEnv; + + UI()->SetActiveItem(pID); + if(m_SelectedQuad != QIndex) + m_SelectedPoints = 0; + m_SelectedQuad = QIndex; + s_LastWx = wx; + s_LastWy = wy; + } + else + { + m_SelectedEnvelopePoint = -1; + m_SelectedQuadEnvelope = -1; + } + } + else + Graphics()->SetColor(0.0f, 1.0f, 0.0f, 1.0f); + + IGraphics::CQuadItem QuadItem(CenterX, CenterY, 5.0f*m_WorldZoom, 5.0f*m_WorldZoom); + Graphics()->QuadsDraw(&QuadItem, 1); +} + void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar) { // render all good stuff @@ -1384,6 +1674,12 @@ pT->ShowInfo(); } } + else + { + // fix aspect ratio of the image in the picker + float Max = min(View.w, View.h); + View.w = View.h = Max; + } static void *s_pEditorID = (void *)&s_pEditorID; int Inside = UI()->MouseInside(&View); @@ -1563,8 +1859,8 @@ { if(!UI()->MouseButton(0)) { - for(int k = 0; k < NumEditLayers; k++) - pEditLayers[k]->FillSelection(m_Brush.IsEmpty(), m_Brush.m_lLayers[0], r); + for(int k = 0; k < NumEditLayers; k++) + pEditLayers[k]->FillSelection(m_Brush.IsEmpty(), m_Brush.m_lLayers[0], r); } else { @@ -1596,10 +1892,10 @@ } } - + CLayerTiles *pLayer = (CLayerTiles*)GetSelectedLayerType(0, LAYERTYPE_TILES); if((Input()->KeyPressed(KEY_LSHIFT) || Input()->KeyPressed(KEY_RSHIFT)) && pLayer) - s_Operation = OP_BRUSH_PAINT; + s_Operation = OP_BRUSH_PAINT; } if(!m_Brush.IsEmpty()) @@ -1656,6 +1952,9 @@ { CLayerQuads *pLayer = (CLayerQuads *)pEditLayers[k]; + if(!m_ShowEnvelopePreview) + m_ShowEnvelopePreview = 2; + Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); for(int i = 0; i < pLayer->m_lQuads.size(); i++) @@ -1705,11 +2004,11 @@ } } - if(GetSelectedGroup() && GetSelectedGroup()->m_UseClipping) + if(!m_ShowPicker && GetSelectedGroup() && GetSelectedGroup()->m_UseClipping) { CLayerGroup *g = m_Map.m_pGameGroup; g->MapScreen(); - + Graphics()->TextureSet(-1); Graphics()->LinesBegin(); @@ -1813,6 +2112,19 @@ Graphics()->LinesEnd(); } + if (!m_ShowPicker && m_ShowTileInfo && m_ShowEnvelopePreview != 0 && GetSelectedLayer(0) && GetSelectedLayer(0)->m_Type == LAYERTYPE_QUADS) + { + GetSelectedGroup()->MapScreen(); + + CLayerQuads *pLayer = (CLayerQuads*)GetSelectedLayer(0); + int TexID = -1; + if(pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size()) + TexID = m_Map.m_lImages[pLayer->m_Image]->m_TexID; + + DoQuadEnvelopes(pLayer->m_lQuads, TexID); + m_ShowEnvelopePreview = 0; + } + Graphics()->MapScreen(UI()->Screen()->x, UI()->Screen()->y, UI()->Screen()->w, UI()->Screen()->h); //UI()->ClipDisable(); } @@ -1908,7 +2220,7 @@ if(pProps[i].m_Value < 0) str_copy(aBuf, "None", sizeof(aBuf)); else - str_format(aBuf, sizeof(aBuf),"%s", m_Map.m_lImages[pProps[i].m_Value]->m_aName); + str_format(aBuf, sizeof(aBuf),"%s", m_Map.m_lImages[pProps[i].m_Value]->m_aName); if(DoButton_Editor(&pIDs[i], aBuf, 0, &Shifter, 0, 0)) PopupSelectImageInvoke(pProps[i].m_Value, UI()->MouseX(), UI()->MouseY()); @@ -2003,8 +2315,6 @@ if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); } - else - ScrollNum = 0; } } @@ -2052,7 +2362,7 @@ static int s_GroupPopupId = 0; if(Result == 2) - UiInvokePopupMenu(&s_GroupPopupId, 0, UI()->MouseX(), UI()->MouseY(), 120, 220, PopupGroup); + UiInvokePopupMenu(&s_GroupPopupId, 0, UI()->MouseX(), UI()->MouseY(), 145, 220, PopupGroup); if(m_Map.m_lGroups[g]->m_lLayers.size() && Input()->MouseDoubleClick()) m_Map.m_lGroups[g]->m_Collapse ^= 1; @@ -2139,16 +2449,22 @@ CEditorImage *pImg = pEditor->m_Map.m_lImages[pEditor->m_SelectedImage]; int External = pImg->m_External; pEditor->Graphics()->UnloadTexture(pImg->m_TexID); + if(pImg->m_pData) + { + mem_free(pImg->m_pData); + pImg->m_pData = 0; + } *pImg = ImgInfo; pImg->m_External = External; pEditor->ExtractName(pFileName, pImg->m_aName, sizeof(pImg->m_aName)); pImg->m_AutoMapper.Load(pImg->m_aName); pImg->m_TexID = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0); + ImgInfo.m_pData = 0; pEditor->SortImages(); for(int i = 0; i < pEditor->m_Map.m_lImages.size(); ++i) { - if(!str_comp(pEditor->m_Map.m_lImages[i]->m_aName, pImg->m_aName)) - pEditor->m_SelectedImage = i; + if(!str_comp(pEditor->m_Map.m_lImages[i]->m_aName, pImg->m_aName)) + pEditor->m_SelectedImage = i; } pEditor->m_Dialog = DIALOG_NONE; } @@ -2165,13 +2481,14 @@ ExtractName(pFileName, aBuf, sizeof(aBuf)); for(int i = 0; i < pEditor->m_Map.m_lImages.size(); ++i) { - if(!str_comp(pEditor->m_Map.m_lImages[i]->m_aName, aBuf)) - return; + if(!str_comp(pEditor->m_Map.m_lImages[i]->m_aName, aBuf)) + return; } CEditorImage *pImg = new CEditorImage(pEditor); *pImg = ImgInfo; pImg->m_TexID = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0); + ImgInfo.m_pData = 0; pImg->m_External = 1; // external by default str_copy(pImg->m_aName, aBuf, sizeof(pImg->m_aName)); pImg->m_AutoMapper.Load(pImg->m_aName); @@ -2292,7 +2609,7 @@ gs_pSortedIndex = 0; } } - + void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View) { @@ -2319,8 +2636,6 @@ if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) s_ScrollValue = clamp(s_ScrollValue + 1.0f/ScrollNum, 0.0f, 1.0f); } - else - ScrollNum = 0; } } @@ -2390,15 +2705,28 @@ r.w = r.h; else r.h = r.w; + float Max = (float)(max(m_Map.m_lImages[i]->m_Width, m_Map.m_lImages[i]->m_Height)); + r.w *= m_Map.m_lImages[i]->m_Width/Max; + r.h *= m_Map.m_lImages[i]->m_Height/Max; Graphics()->TextureSet(m_Map.m_lImages[i]->m_TexID); Graphics()->BlendNormal(); + Graphics()->WrapClamp(); Graphics()->QuadsBegin(); IGraphics::CQuadItem QuadItem(r.x, r.y, r.w, r.h); Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsEnd(); - + Graphics()->WrapNormal(); } } + + // separator + ToolBox.HSplitTop(5.0f, &Slot, &ToolBox); + ImageCur += 5.0f; + IGraphics::CLineItem LineItem(Slot.x, Slot.y+Slot.h/2, Slot.x+Slot.w, Slot.y+Slot.h/2); + Graphics()->TextureSet(-1); + Graphics()->LinesBegin(); + Graphics()->LinesDraw(&LineItem, 1); + Graphics()->LinesEnd(); } if(ImageCur + 27.0f > ImageStopAt) @@ -2409,7 +2737,6 @@ // new image static int s_NewImageButton = 0; - ToolBox.HSplitTop(10.0f, &Slot, &ToolBox); ToolBox.HSplitTop(12.0f, &Slot, &ToolBox); if(DoButton_Editor(&s_NewImageButton, "Add", 0, &Slot, 0, "Load a new image to use in the map")) InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_IMG, "Add Image", "Add", "mapres", "", AddImage, this); @@ -2485,11 +2812,13 @@ RenderTools()->DrawUIRect(&View, vec4(0,0,0,0.75f), CUI::CORNER_ALL, 5.0f); View.Margin(10.0f, &View); - CUIRect Title, FileBox, FileBoxLabel, ButtonBar, Scroll; + CUIRect Title, FileBox, FileBoxLabel, ButtonBar, Scroll, PathBox; View.HSplitTop(18.0f, &Title, &View); View.HSplitTop(5.0f, 0, &View); // some spacing View.HSplitBottom(14.0f, &View, &ButtonBar); View.HSplitBottom(10.0f, &View, 0); // some spacing + View.HSplitBottom(14.0f, &View, &PathBox); + View.HSplitBottom(5.0f, &View, 0); // some spacing View.HSplitBottom(14.0f, &View, &FileBox); FileBox.VSplitLeft(55.0f, &FileBoxLabel, &FileBox); View.HSplitBottom(10.0f, &View, 0); // some spacing @@ -2500,6 +2829,15 @@ Title.VMargin(10.0f, &Title); UI()->DoLabel(&Title, m_pFileDialogTitle, 12.0f, -1, -1); + // pathbox + char aPath[128], aBuf[128]; + if(m_FilesSelectedIndex != -1) + Storage()->GetCompletePath(m_FileList[m_FilesSelectedIndex].m_StorageType, m_pFileDialogPath, aPath, sizeof(aPath)); + else + aPath[0] = 0; + str_format(aBuf, sizeof(aBuf), "Current path: %s", aPath); + UI()->DoLabel(&PathBox, aBuf, 10.0f, -1, -1); + // filebox if(m_FileDialogStorageType == IStorage::TYPE_SAVE) { @@ -2596,6 +2934,7 @@ static int s_OkButton = 0; static int s_CancelButton = 0; static int s_NewFolderButton = 0; + static int s_MapInfoButton = 0; CUIRect Button; ButtonBar.VSplitRight(50.0f, &ButtonBar, &Button); @@ -2671,6 +3010,22 @@ UI()->SetActiveItem(0); } } + + if(m_FileDialogStorageType == IStorage::TYPE_SAVE) + { + ButtonBar.VSplitLeft(40.0f, 0, &ButtonBar); + ButtonBar.VSplitLeft(70.0f, &Button, &ButtonBar); + if(DoButton_Editor(&s_MapInfoButton, "Map details", 0, &Button, 0, 0)) + { + str_copy(m_Map.m_MapInfo.m_aAuthorTmp, m_Map.m_MapInfo.m_aAuthor, sizeof(m_Map.m_MapInfo.m_aAuthorTmp)); + str_copy(m_Map.m_MapInfo.m_aVersionTmp, m_Map.m_MapInfo.m_aVersion, sizeof(m_Map.m_MapInfo.m_aVersionTmp)); + str_copy(m_Map.m_MapInfo.m_aCreditsTmp, m_Map.m_MapInfo.m_aCredits, sizeof(m_Map.m_MapInfo.m_aCreditsTmp)); + str_copy(m_Map.m_MapInfo.m_aLicenseTmp, m_Map.m_MapInfo.m_aLicense, sizeof(m_Map.m_MapInfo.m_aLicenseTmp)); + static int s_MapInfoPopupID = 0; + UiInvokePopupMenu(&s_MapInfoPopupID, 0, Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, PopupMapInfo); + UI()->SetActiveItem(0); + } + } } void CEditor::FilelistPopulate(int StorageType) @@ -2711,7 +3066,7 @@ str_copy(m_aFileDialogFileName, pDefaultName, sizeof(m_aFileDialogFileName)); if(pBasePath) str_copy(m_aFileDialogCurrentFolder, pBasePath, sizeof(m_aFileDialogCurrentFolder)); - + FilelistPopulate(m_FileDialogStorageType); m_Dialog = DIALOG_FILE; @@ -2731,10 +3086,10 @@ const char *pButName = m_Mode == MODE_LAYERS ? "Layers" : "Images"; if(DoButton_Tab(&s_Button, pButName, 0, &Button, 0, "Switch between images and layers managment.")) { - if(m_Mode == MODE_LAYERS) - m_Mode = MODE_IMAGES; - else - m_Mode = MODE_LAYERS; + if(m_Mode == MODE_LAYERS) + m_Mode = MODE_IMAGES; + else + m_Mode = MODE_LAYERS; } } @@ -2908,6 +3263,17 @@ if(DoButton_Editor(&s_aChannelButtons[i], s_paNames[pEnvelope->m_Channels-3][i], s_ActiveChannels&Bit, &Button, 0, paDescriptions[pEnvelope->m_Channels-3][i])) s_ActiveChannels ^= Bit; } + + // sync checkbox + ToolBar.VSplitLeft(15.0f, &Button, &ToolBar); + ToolBar.VSplitLeft(12.0f, &Button, &ToolBar); + static int s_SyncButton; + if(DoButton_Editor(&s_SyncButton, pEnvelope->m_Synchronized?"X":"", 0, &Button, 0, "Enable envelope synchronization between clients")) + pEnvelope->m_Synchronized = !pEnvelope->m_Synchronized; + + ToolBar.VSplitLeft(4.0f, &Button, &ToolBar); + ToolBar.VSplitLeft(80.0f, &Button, &ToolBar); + UI()->DoLabel(&Button, "Synchronized", 10.0f, -1, -1); } float EndTime = pEnvelope->EndTime(); @@ -2947,6 +3313,7 @@ m_Map.m_Modified = true; } + m_ShowEnvelopePreview = 1; m_pTooltip = "Press right mouse button to create a new point"; } } @@ -3085,10 +3452,13 @@ { if(!UI()->MouseButton(0)) { + m_SelectedQuadEnvelope = -1; + m_SelectedEnvelopePoint = -1; + UI()->SetActiveItem(0); } else - { + { if(Input()->KeyPressed(KEY_LSHIFT) || Input()->KeyPressed(KEY_RSHIFT)) { if(i != 0) @@ -3110,6 +3480,10 @@ else pEnvelope->m_lPoints[i].m_aValues[c] -= f2fx(m_MouseDeltaY*ValueScale); } + + m_SelectedQuadEnvelope = m_SelectedEnvelope; + m_ShowEnvelopePreview = 1; + m_SelectedEnvelopePoint = i; m_Map.m_Modified = true; } @@ -3132,6 +3506,7 @@ m_Map.m_Modified = true; } + m_ShowEnvelopePreview = 1; ColorMod = 100.0f; Graphics()->SetColor(1,0.75f,0.75f,1); m_pTooltip = "Left mouse to drag. Hold ctrl to be more precise. Hold shift to alter time point aswell. Right click to delete."; @@ -3143,7 +3518,10 @@ CurrentValue = pEnvelope->m_lPoints[i].m_aValues[c]; } - Graphics()->SetColor(aColors[c].r*ColorMod, aColors[c].g*ColorMod, aColors[c].b*ColorMod, 1.0f); + if (m_SelectedQuadEnvelope == m_SelectedEnvelope && m_SelectedEnvelopePoint == i) + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + else + Graphics()->SetColor(aColors[c].r*ColorMod, aColors[c].g*ColorMod, aColors[c].b*ColorMod, 1.0f); IGraphics::CQuadItem QuadItem(Final.x, Final.y, Final.w, Final.h); Graphics()->QuadsDrawTL(&QuadItem, 1); } @@ -3266,10 +3644,15 @@ (void)0; */ + CUIRect Info; MenuBar.VSplitLeft(40.0f, 0, &MenuBar); + MenuBar.VSplitLeft(MenuBar.w*0.75f, &MenuBar, &Info); char aBuf[128]; str_format(aBuf, sizeof(aBuf), "File: %s", m_aFileName); UI()->DoLabel(&MenuBar, aBuf, 10.0f, -1, -1); + + str_format(aBuf, sizeof(aBuf), "Z: %i, A: %.1f, G: %i", m_ZoomLevel, m_AnimateSpeed, m_GridFactor); + UI()->DoLabel(&Info, aBuf, 10.0f, 1, -1); } void CEditor::Render() @@ -3285,6 +3668,9 @@ // reset tip m_pTooltip = 0; + if(m_EditBoxActive) + --m_EditBoxActive; + // render checker RenderBackground(View, ms_CheckerTexture, 32.0f, 1.0f); @@ -3314,7 +3700,17 @@ if(m_Mode == MODE_LAYERS) DoMapEditor(View, ToolBar); - // do the scrolling + // do zooming + if(Input()->KeyDown(KEY_KP_MINUS)) + m_ZoomLevel += 50; + if(Input()->KeyDown(KEY_KP_PLUS)) + m_ZoomLevel -= 50; + if(Input()->KeyDown(KEY_KP_MULTIPLY)) + { + m_EditorOffsetX = 0; + m_EditorOffsetY = 0; + m_ZoomLevel = 100; + } if(m_Dialog == DIALOG_NONE && UI()->MouseInside(&View)) { if(Input()->KeyPresses(KEY_MOUSE_WHEEL_UP)) @@ -3322,9 +3718,9 @@ if(Input()->KeyPresses(KEY_MOUSE_WHEEL_DOWN)) m_ZoomLevel += 20; - - m_ZoomLevel = clamp(m_ZoomLevel, 50, 2000); } + m_ZoomLevel = clamp(m_ZoomLevel, 50, 2000); + m_WorldZoom = m_ZoomLevel/100.0f; if(m_GuiActive) { @@ -3382,6 +3778,7 @@ static int s_PopupID = 0; UiInvokePopupMenu(&s_PopupID, 0, Width/2.0f-200.0f, Height/2.0f-100.0f, 400.0f, 200.0f, PopupEvent); m_PopupEventActivated = false; + m_PopupEventWasActivated = true; } @@ -3443,12 +3840,12 @@ m_SelectedPoints = 0; m_SelectedEnvelope = 0; m_SelectedImage = 0; - + m_WorldOffsetX = 0; m_WorldOffsetY = 0; m_EditorOffsetX = 0.0f; m_EditorOffsetY = 0.0f; - + m_WorldZoom = 1.0f; m_ZoomLevel = 200; @@ -3458,6 +3855,8 @@ m_MouseDeltaWy = 0; m_Map.m_Modified = false; + + m_ShowEnvelopePreview = 0; } int CEditor::GetLineDistance() @@ -3490,18 +3889,26 @@ for(int j = 0; j < m_lGroups[i]->m_lLayers.size(); ++j) if(m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_QUADS) { - CLayerQuads *Layer = static_cast(m_lGroups[i]->m_lLayers[j]); - for(int k = 0; k < Layer->m_lQuads.size(); ++k) + CLayerQuads *pLayer = static_cast(m_lGroups[i]->m_lLayers[j]); + for(int k = 0; k < pLayer->m_lQuads.size(); ++k) { - if(Layer->m_lQuads[k].m_PosEnv == Index) - Layer->m_lQuads[k].m_PosEnv = -1; - else if(Layer->m_lQuads[k].m_PosEnv > Index) - Layer->m_lQuads[k].m_PosEnv--; - if(Layer->m_lQuads[k].m_ColorEnv == Index) - Layer->m_lQuads[k].m_ColorEnv = -1; - else if(Layer->m_lQuads[k].m_ColorEnv > Index) - Layer->m_lQuads[k].m_ColorEnv--; - } + if(pLayer->m_lQuads[k].m_PosEnv == Index) + pLayer->m_lQuads[k].m_PosEnv = -1; + else if(pLayer->m_lQuads[k].m_PosEnv > Index) + pLayer->m_lQuads[k].m_PosEnv--; + if(pLayer->m_lQuads[k].m_ColorEnv == Index) + pLayer->m_lQuads[k].m_ColorEnv = -1; + else if(pLayer->m_lQuads[k].m_ColorEnv > Index) + pLayer->m_lQuads[k].m_ColorEnv--; + } + } + else if(m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_TILES) + { + CLayerTiles *pLayer = static_cast(m_lGroups[i]->m_lLayers[j]); + if(pLayer->m_ColorEnv == Index) + pLayer->m_ColorEnv = -1; + if(pLayer->m_ColorEnv > Index) + pLayer->m_ColorEnv--; } m_lEnvelopes.remove_index(Index); @@ -3529,6 +3936,8 @@ m_lEnvelopes.delete_all(); m_lImages.delete_all(); + m_MapInfo.Reset(); + m_pGameLayer = 0x0; m_pGameGroup = 0x0; @@ -3594,19 +4003,19 @@ void CEditor::DoMapBorder() { - CLayerTiles *pT = (CLayerTiles *)GetSelectedLayerType(0, LAYERTYPE_TILES); - - for(int i = 0; i < pT->m_Width*2; ++i) - pT->m_pTiles[i].m_Index = 1; - - for(int i = 0; i < pT->m_Width*pT->m_Height; ++i) - { - if(i%pT->m_Width < 2 || i%pT->m_Width > pT->m_Width-3) - pT->m_pTiles[i].m_Index = 1; - } - - for(int i = (pT->m_Width*(pT->m_Height-2)); i < pT->m_Width*pT->m_Height; ++i) - pT->m_pTiles[i].m_Index = 1; + CLayerTiles *pT = (CLayerTiles *)GetSelectedLayerType(0, LAYERTYPE_TILES); + + for(int i = 0; i < pT->m_Width*2; ++i) + pT->m_pTiles[i].m_Index = 1; + + for(int i = 0; i < pT->m_Width*pT->m_Height; ++i) + { + if(i%pT->m_Width < 2 || i%pT->m_Width > pT->m_Width-3) + pT->m_pTiles[i].m_Index = 1; + } + + for(int i = (pT->m_Width*(pT->m_Height-2)); i < pT->m_Width*pT->m_Height; ++i) + pT->m_pTiles[i].m_Index = 1; } void CEditor::UpdateAndRender() diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/editor.h teeworlds-0.6.2+dfsg/src/game/editor/editor.h --- teeworlds-0.6.1+dfsg/src/game/editor/editor.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/editor.h 2013-05-01 11:47:39.000000000 +0000 @@ -51,6 +51,7 @@ array m_lPoints; char m_aName[32]; float m_Bottom, m_Top; + bool m_Synchronized; CEnvelope(int Chan) { @@ -58,6 +59,7 @@ m_aName[0] = 0; m_Bottom = 0; m_Top = 0; + m_Synchronized = true; } void Resort() @@ -274,6 +276,34 @@ array m_lImages; array m_lEnvelopes; + class CMapInfo + { + public: + char m_aAuthorTmp[32]; + char m_aVersionTmp[16]; + char m_aCreditsTmp[128]; + char m_aLicenseTmp[32]; + + char m_aAuthor[32]; + char m_aVersion[16]; + char m_aCredits[128]; + char m_aLicense[32]; + + void Reset() + { + m_aAuthorTmp[0] = 0; + m_aVersionTmp[0] = 0; + m_aCreditsTmp[0] = 0; + m_aLicenseTmp[0] = 0; + + m_aAuthor[0] = 0; + m_aVersion[0] = 0; + m_aCredits[0] = 0; + m_aLicense[0] = 0; + } + }; + CMapInfo m_MapInfo; + class CLayerGame *m_pGameLayer; CLayerGroup *m_pGameGroup; @@ -476,6 +506,7 @@ m_Mode = MODE_LAYERS; m_Dialog = 0; + m_EditBoxActive = 0; m_pTooltip = 0; m_GridActive = false; @@ -486,6 +517,7 @@ m_ValidSaveFilename = false; m_PopupEventActivated = false; + m_PopupEventWasActivated = false; m_FileDialogStorageType = 0; m_pFileDialogTitle = 0; @@ -528,6 +560,10 @@ m_ShowEnvelopeEditor = 0; + m_ShowEnvelopePreview = 0; + m_SelectedQuadEnvelope = -1; + m_SelectedEnvelopePoint = -1; + ms_CheckerTexture = 0; ms_BackgroundTexture = 0; ms_CursorTexture = 0; @@ -560,6 +596,7 @@ int m_Mode; int m_Dialog; + int m_EditBoxActive; const char *m_pTooltip; bool m_GridActive; @@ -579,6 +616,7 @@ int m_PopupEventType; int m_PopupEventActivated; + int m_PopupEventWasActivated; enum { @@ -644,6 +682,7 @@ float m_AnimateSpeed; int m_ShowEnvelopeEditor; + int m_ShowEnvelopePreview; //Values: 0-Off|1-Selected Envelope|2-All bool m_ShowPicker; int m_SelectedLayer; @@ -651,6 +690,8 @@ int m_SelectedQuad; int m_SelectedPoints; int m_SelectedEnvelope; + int m_SelectedEnvelopePoint; + int m_SelectedQuadEnvelope; int m_SelectedImage; static int ms_CheckerTexture; @@ -697,6 +738,7 @@ static int PopupQuad(CEditor *pEditor, CUIRect View); static int PopupPoint(CEditor *pEditor, CUIRect View); static int PopupNewFolder(CEditor *pEditor, CUIRect View); + static int PopupMapInfo(CEditor *pEditor, CUIRect View); static int PopupEvent(CEditor *pEditor, CUIRect View); static int PopupSelectImage(CEditor *pEditor, CUIRect View); static int PopupSelectGametileOp(CEditor *pEditor, CUIRect View); @@ -713,13 +755,16 @@ void PopupSelectGametileOpInvoke(float x, float y); int PopupSelectGameTileOpResult(); - + void PopupSelectConfigAutoMapInvoke(float x, float y); int PopupSelectConfigAutoMapResult(); vec4 ButtonColorMul(const void *pID); + void DoQuadEnvelopes(const array &m_lQuads, int TexID = -1); + void DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int pIndex); void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v); + void DoMapEditor(CUIRect View, CUIRect Toolbar); void DoToolbar(CUIRect Toolbar); void DoQuad(CQuad *pQuad, int Index); diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/io.cpp teeworlds-0.6.2+dfsg/src/game/editor/io.cpp --- teeworlds-0.6.1+dfsg/src/game/editor/io.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/io.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -220,6 +220,31 @@ df.AddItem(MAPITEMTYPE_VERSION, 0, sizeof(Item), &Item); } + // save map info + { + CMapItemInfo Item; + Item.m_Version = 1; + + if(m_MapInfo.m_aAuthor[0]) + Item.m_Author = df.AddData(str_length(m_MapInfo.m_aAuthor)+1, m_MapInfo.m_aAuthor); + else + Item.m_Author = -1; + if(m_MapInfo.m_aVersion[0]) + Item.m_MapVersion = df.AddData(str_length(m_MapInfo.m_aVersion)+1, m_MapInfo.m_aVersion); + else + Item.m_MapVersion = -1; + if(m_MapInfo.m_aCredits[0]) + Item.m_Credits = df.AddData(str_length(m_MapInfo.m_aCredits)+1, m_MapInfo.m_aCredits); + else + Item.m_Credits = -1; + if(m_MapInfo.m_aLicense[0]) + Item.m_License = df.AddData(str_length(m_MapInfo.m_aLicense)+1, m_MapInfo.m_aLicense); + else + Item.m_License = -1; + + df.AddItem(MAPITEMTYPE_INFO, 0, sizeof(Item), &Item); + } + // save images for(int i = 0; i < m_lImages.size(); i++) { @@ -342,10 +367,11 @@ for(int e = 0; e < m_lEnvelopes.size(); e++) { CMapItemEnvelope Item; - Item.m_Version = 1; + Item.m_Version = CMapItemEnvelope::CURRENT_VERSION; Item.m_Channels = m_lEnvelopes[e]->m_Channels; Item.m_StartPoint = PointCount; Item.m_NumPoints = m_lEnvelopes[e]->m_lPoints.size(); + Item.m_Synchronized = m_lEnvelopes[e]->m_Synchronized; StrToInts(Item.m_aName, sizeof(Item.m_aName)/sizeof(int), m_lEnvelopes[e]->m_aName); df.AddItem(MAPITEMTYPE_ENVELOPE, e, sizeof(Item), &Item); @@ -365,6 +391,7 @@ } df.AddItem(MAPITEMTYPE_ENVPOINTS, 0, TotalSize, pPoints); + mem_free(pPoints); // finish the data file df.Finish(); @@ -413,6 +440,22 @@ { //editor.reset(false); + // load map info + { + CMapItemInfo *pItem = (CMapItemInfo *)DataFile.FindItem(MAPITEMTYPE_INFO, 0); + if(pItem && pItem->m_Version == 1) + { + if(pItem->m_Author > -1) + str_copy(m_MapInfo.m_aAuthor, (char *)DataFile.GetData(pItem->m_Author), sizeof(m_MapInfo.m_aAuthor)); + if(pItem->m_MapVersion > -1) + str_copy(m_MapInfo.m_aVersion, (char *)DataFile.GetData(pItem->m_MapVersion), sizeof(m_MapInfo.m_aVersion)); + if(pItem->m_Credits > -1) + str_copy(m_MapInfo.m_aCredits, (char *)DataFile.GetData(pItem->m_Credits), sizeof(m_MapInfo.m_aCredits)); + if(pItem->m_License > -1) + str_copy(m_MapInfo.m_aLicense, (char *)DataFile.GetData(pItem->m_License), sizeof(m_MapInfo.m_aLicense)); + } + } + // load images { int Start, Num; @@ -437,6 +480,7 @@ { *pImg = ImgInfo; pImg->m_TexID = m_pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0); + ImgInfo.m_pData = 0; pImg->m_External = 1; } } @@ -601,6 +645,8 @@ if(pItem->m_aName[0] != -1) // compatibility with old maps IntsToStr(pItem->m_aName, sizeof(pItem->m_aName)/sizeof(int), pEnv->m_aName); m_lEnvelopes.add(pEnv); + if(pItem->m_Version >= 2) + pEnv->m_Synchronized = pItem->m_Synchronized; } } } diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/layer_quads.cpp teeworlds-0.6.2+dfsg/src/game/editor/layer_quads.cpp --- teeworlds-0.6.1+dfsg/src/game/editor/layer_quads.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/layer_quads.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -27,7 +27,10 @@ if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size()) Graphics()->TextureSet(m_pEditor->m_Map.m_lImages[m_Image]->m_TexID); - m_pEditor->RenderTools()->RenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_OPAQUE|LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor); + Graphics()->BlendNone(); + m_pEditor->RenderTools()->RenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_OPAQUE, m_pEditor->EnvelopeEval, m_pEditor); + Graphics()->BlendNormal(); + m_pEditor->RenderTools()->RenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor); } CQuad *CLayerQuads::NewQuad() diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/layer_tiles.cpp teeworlds-0.6.2+dfsg/src/game/editor/layer_tiles.cpp --- teeworlds-0.6.1+dfsg/src/game/editor/layer_tiles.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/layer_tiles.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -64,7 +64,11 @@ m_TexID = m_pEditor->m_Map.m_lImages[m_Image]->m_TexID; Graphics()->TextureSet(m_TexID); vec4 Color = vec4(m_Color.r/255.0f, m_Color.g/255.0f, m_Color.b/255.0f, m_Color.a/255.0f); - m_pEditor->RenderTools()->RenderTilemap(m_pTiles, m_Width, m_Height, 32.0f, Color, LAYERRENDERFLAG_OPAQUE|LAYERRENDERFLAG_TRANSPARENT, + Graphics()->BlendNone(); + m_pEditor->RenderTools()->RenderTilemap(m_pTiles, m_Width, m_Height, 32.0f, Color, LAYERRENDERFLAG_OPAQUE, + m_pEditor->EnvelopeEval, m_pEditor, m_ColorEnv, m_ColorEnvOffset); + Graphics()->BlendNormal(); + m_pEditor->RenderTools()->RenderTilemap(m_pTiles, m_Width, m_Height, 32.0f, Color, LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor, m_ColorEnv, m_ColorEnvOffset); } @@ -159,6 +163,8 @@ if(m_Readonly) return; + Snap(&Rect); + int sx = ConvertX(Rect.x); int sy = ConvertY(Rect.y); int w = ConvertX(Rect.w); @@ -166,9 +172,9 @@ CLayerTiles *pLt = static_cast(pBrush); - for(int y = 0; y <= h; y++) + for(int y = 0; y < h; y++) { - for(int x = 0; x <= w; x++) + for(int x = 0; x < w; x++) { int fx = x+sx; int fy = y+sy; @@ -332,6 +338,7 @@ float ScreenX0, ScreenY0, ScreenX1, ScreenY1; Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); Graphics()->TextureSet(m_pEditor->Client()->GetDebugFont()); + Graphics()->QuadsBegin(); int StartY = max(0, (int)(ScreenY0/32.0f)-1); int StartX = max(0, (int)(ScreenX0/32.0f)-1); @@ -346,24 +353,25 @@ { char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%i", m_pTiles[c].m_Index); - m_pEditor->Graphics()->QuadsText(x*32, y*32, 16.0f, 1,1,1,1, aBuf); + m_pEditor->Graphics()->QuadsText(x*32, y*32, 16.0f, aBuf); char aFlags[4] = { m_pTiles[c].m_Flags&TILEFLAG_VFLIP ? 'V' : ' ', m_pTiles[c].m_Flags&TILEFLAG_HFLIP ? 'H' : ' ', m_pTiles[c].m_Flags&TILEFLAG_ROTATE? 'R' : ' ', 0}; - m_pEditor->Graphics()->QuadsText(x*32, y*32+16, 16.0f, 1,1,1,1, aFlags); + m_pEditor->Graphics()->QuadsText(x*32, y*32+16, 16.0f, aFlags); } x += m_pTiles[c].m_Skip; } + Graphics()->QuadsEnd(); Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } int CLayerTiles::RenderProperties(CUIRect *pToolBox) { CUIRect Button; - + bool InGameGroup = !find_linear(m_pEditor->m_Map.m_pGameGroup->m_lLayers.all(), this).empty(); if(m_pEditor->m_Map.m_pGameLayer != this) { @@ -373,7 +381,7 @@ pToolBox->HSplitBottom(12.0f, pToolBox, &Button); if(m_pEditor->DoButton_Editor(&s_AutoMapperButton, "Auto map", 0, &Button, 0, "")) m_pEditor->PopupSelectConfigAutoMapInvoke(m_pEditor->UI()->MouseX(), m_pEditor->UI()->MouseY()); - + int Result = m_pEditor->PopupSelectConfigAutoMapResult(); if(Result > -1) { @@ -473,7 +481,19 @@ m_Color.a = NewVal&0xff; } if(Prop == PROP_COLOR_ENV) - m_ColorEnv = clamp(NewVal-1, -1, m_pEditor->m_Map.m_lEnvelopes.size()-1); + { + int Index = clamp(NewVal-1, -1, m_pEditor->m_Map.m_lEnvelopes.size()-1); + int Step = (Index-m_ColorEnv)%2; + if(Step != 0) + { + for(; Index >= -1 && Index < m_pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + if(Index == -1 || m_pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 4) + { + m_ColorEnv = Index; + break; + } + } + } if(Prop == PROP_COLOR_ENV_OFFSET) m_ColorEnvOffset = NewVal; diff -Nru teeworlds-0.6.1+dfsg/src/game/editor/popups.cpp teeworlds-0.6.2+dfsg/src/game/editor/popups.cpp --- teeworlds-0.6.1+dfsg/src/game/editor/popups.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/editor/popups.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -458,9 +458,35 @@ for(int k = 0; k < 5; ++k) pQuad->m_aPoints[k].y += Offset; } - if(Prop == PROP_POS_ENV) pQuad->m_PosEnv = clamp(NewVal-1, -1, pEditor->m_Map.m_lEnvelopes.size()-1); + if(Prop == PROP_POS_ENV) + { + int Index = clamp(NewVal-1, -1, pEditor->m_Map.m_lEnvelopes.size()-1); + int Step = (Index-pQuad->m_PosEnv)%2; + if(Step != 0) + { + for(; Index >= -1 && Index < pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + if(Index == -1 || pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 3) + { + pQuad->m_PosEnv = Index; + break; + } + } + } if(Prop == PROP_POS_ENV_OFFSET) pQuad->m_PosEnvOffset = NewVal; - if(Prop == PROP_COLOR_ENV) pQuad->m_ColorEnv = clamp(NewVal-1, -1, pEditor->m_Map.m_lEnvelopes.size()-1); + if(Prop == PROP_COLOR_ENV) + { + int Index = clamp(NewVal-1, -1, pEditor->m_Map.m_lEnvelopes.size()-1); + int Step = (Index-pQuad->m_ColorEnv)%2; + if(Step != 0) + { + for(; Index >= -1 && Index < pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + if(Index == -1 || pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 4) + { + pQuad->m_ColorEnv = Index; + break; + } + } + } if(Prop == PROP_COLOR_ENV_OFFSET) pQuad->m_ColorEnvOffset = NewVal; return 0; @@ -528,7 +554,6 @@ { if(pEditor->m_SelectedPoints&(1<m_aColors[v].r = (NewVal>>24)&0xff; pQuad->m_aColors[v].g = (NewVal>>16)&0xff; pQuad->m_aColors[v].b = (NewVal>>8)&0xff; @@ -609,6 +634,74 @@ return 0; } +int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View) +{ + CUIRect Label, ButtonBar, Button; + + // title + View.HSplitTop(10.0f, 0, &View); + View.HSplitTop(30.0f, &Label, &View); + pEditor->UI()->DoLabel(&Label, "Map details", 20.0f, 0); + + View.HSplitBottom(10.0f, &View, 0); + View.HSplitBottom(20.0f, &View, &ButtonBar); + + View.VMargin(40.0f, &View); + + // author box + View.HSplitTop(20.0f, &Label, &View); + pEditor->UI()->DoLabel(&Label, "Author:", 10.0f, -1); + Label.VSplitLeft(40.0f, 0, &Button); + Button.HSplitTop(12.0f, &Button, 0); + static float s_AuthorBox = 0; + pEditor->DoEditBox(&s_AuthorBox, &Button, pEditor->m_Map.m_MapInfo.m_aAuthorTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aAuthorTmp), 10.0f, &s_AuthorBox); + + // version box + View.HSplitTop(20.0f, &Label, &View); + pEditor->UI()->DoLabel(&Label, "Version:", 10.0f, -1); + Label.VSplitLeft(40.0f, 0, &Button); + Button.HSplitTop(12.0f, &Button, 0); + static float s_VersionBox = 0; + pEditor->DoEditBox(&s_VersionBox, &Button, pEditor->m_Map.m_MapInfo.m_aVersionTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aVersionTmp), 10.0f, &s_VersionBox); + + // credits box + View.HSplitTop(20.0f, &Label, &View); + pEditor->UI()->DoLabel(&Label, "Credits:", 10.0f, -1); + Label.VSplitLeft(40.0f, 0, &Button); + Button.HSplitTop(12.0f, &Button, 0); + static float s_CreditsBox = 0; + pEditor->DoEditBox(&s_CreditsBox, &Button, pEditor->m_Map.m_MapInfo.m_aCreditsTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aCreditsTmp), 10.0f, &s_CreditsBox); + + // license box + View.HSplitTop(20.0f, &Label, &View); + pEditor->UI()->DoLabel(&Label, "License:", 10.0f, -1); + Label.VSplitLeft(40.0f, 0, &Button); + Button.HSplitTop(12.0f, &Button, 0); + static float s_LicenseBox = 0; + pEditor->DoEditBox(&s_LicenseBox, &Button, pEditor->m_Map.m_MapInfo.m_aLicenseTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aLicenseTmp), 10.0f, &s_LicenseBox); + + // button bar + ButtonBar.VSplitLeft(30.0f, 0, &ButtonBar); + ButtonBar.VSplitLeft(110.0f, &Label, &ButtonBar); + static int s_CreateButton = 0; + if(pEditor->DoButton_Editor(&s_CreateButton, "Save", 0, &Label, 0, 0)) + { + str_copy(pEditor->m_Map.m_MapInfo.m_aAuthor, pEditor->m_Map.m_MapInfo.m_aAuthorTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aAuthor)); + str_copy(pEditor->m_Map.m_MapInfo.m_aVersion, pEditor->m_Map.m_MapInfo.m_aVersionTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aVersion)); + str_copy(pEditor->m_Map.m_MapInfo.m_aCredits, pEditor->m_Map.m_MapInfo.m_aCreditsTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aCredits)); + str_copy(pEditor->m_Map.m_MapInfo.m_aLicense, pEditor->m_Map.m_MapInfo.m_aLicenseTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aLicense)); + return 1; + } + + ButtonBar.VSplitRight(30.0f, &ButtonBar, 0); + ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label); + static int s_AbortButton = 0; + if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, 0)) + return 1; + + return 0; +} + int CEditor::PopupEvent(CEditor *pEditor, CUIRect View) { CUIRect Label, ButtonBar; @@ -658,13 +751,17 @@ } else if(pEditor->m_PopupEventType == POPEVENT_SAVE) pEditor->CallbackSaveMap(pEditor->m_aFileSaveName, IStorage::TYPE_SAVE, pEditor); + pEditor->m_PopupEventWasActivated = false; return 1; } ButtonBar.VSplitRight(30.0f, &ButtonBar, 0); ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label); static int s_AbortButton = 0; if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, 0)) + { + pEditor->m_PopupEventWasActivated = false; return 1; + } return 0; } @@ -703,13 +800,23 @@ } if(ShowImage >= 0 && ShowImage < pEditor->m_Map.m_lImages.size()) + { + if(ImageView.h < ImageView.w) + ImageView.w = ImageView.h; + else + ImageView.h = ImageView.w; + float Max = (float)(max(pEditor->m_Map.m_lImages[ShowImage]->m_Width, pEditor->m_Map.m_lImages[ShowImage]->m_Height)); + ImageView.w *= pEditor->m_Map.m_lImages[ShowImage]->m_Width/Max; + ImageView.h *= pEditor->m_Map.m_lImages[ShowImage]->m_Height/Max; pEditor->Graphics()->TextureSet(pEditor->m_Map.m_lImages[ShowImage]->m_TexID); - else - pEditor->Graphics()->TextureSet(-1); - pEditor->Graphics()->QuadsBegin(); - IGraphics::CQuadItem QuadItem(ImageView.x, ImageView.y, ImageView.w, ImageView.h); - pEditor->Graphics()->QuadsDrawTL(&QuadItem, 1); - pEditor->Graphics()->QuadsEnd(); + pEditor->Graphics()->BlendNormal(); + pEditor->Graphics()->WrapClamp(); + pEditor->Graphics()->QuadsBegin(); + IGraphics::CQuadItem QuadItem(ImageView.x, ImageView.y, ImageView.w, ImageView.h); + pEditor->Graphics()->QuadsDrawTL(&QuadItem, 1); + pEditor->Graphics()->QuadsEnd(); + pEditor->Graphics()->WrapNormal(); + } return 0; } @@ -776,7 +883,7 @@ CUIRect Button; static int s_AutoMapperConfigButtons[256]; CAutoMapper *pAutoMapper = &pEditor->m_Map.m_lImages[pLayer->m_Image]->m_AutoMapper; - + for(int i = 0; i < pAutoMapper->ConfigNamesNum(); ++i) { View.HSplitTop(2.0f, 0, &View); @@ -802,7 +909,7 @@ { if(s_AutoMapConfigSelected < 0) return -1; - + int Result = s_AutoMapConfigSelected; s_AutoMapConfigSelected = -1; return Result; diff -Nru teeworlds-0.6.1+dfsg/src/game/gamecore.cpp teeworlds-0.6.2+dfsg/src/game/gamecore.cpp --- teeworlds-0.6.1+dfsg/src/game/gamecore.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/gamecore.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -302,7 +302,7 @@ } } - if(m_pWorld && m_pWorld->m_Tuning.m_PlayerCollision) + if(m_pWorld) { for(int i = 0; i < MAX_CLIENTS; i++) { @@ -317,7 +317,7 @@ // handle player <-> player collision float Distance = distance(m_Pos, pCharCore->m_Pos); vec2 Dir = normalize(m_Pos - pCharCore->m_Pos); - if(Distance < PhysSize*1.25f && Distance > 0.0f) + if(m_pWorld->m_Tuning.m_PlayerCollision && Distance < PhysSize*1.25f && Distance > 0.0f) { float a = (PhysSize*1.45f - Distance); float Velocity = 0.5f; @@ -332,7 +332,7 @@ } // handle hook influence - if(m_HookedPlayer == i) + if(m_HookedPlayer == i && m_pWorld->m_Tuning.m_PlayerHooking) { if(Distance > PhysSize*1.50f) // TODO: fix tweakable variable { diff -Nru teeworlds-0.6.1+dfsg/src/game/layers.cpp teeworlds-0.6.2+dfsg/src/game/layers.cpp --- teeworlds-0.6.1+dfsg/src/game/layers.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/layers.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -29,7 +29,7 @@ if(pLayer->m_Type == LAYERTYPE_TILES) { CMapItemLayerTilemap *pTilemap = reinterpret_cast(pLayer); - if(pTilemap->m_Flags&1) + if(pTilemap->m_Flags&TILESLAYERFLAG_GAME) { m_pGameLayer = pTilemap; m_pGameGroup = pGroup; diff -Nru teeworlds-0.6.1+dfsg/src/game/mapitems.h teeworlds-0.6.2+dfsg/src/game/mapitems.h --- teeworlds-0.6.1+dfsg/src/game/mapitems.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/mapitems.h 2013-05-01 11:47:39.000000000 +0000 @@ -7,7 +7,7 @@ enum { LAYERTYPE_INVALID=0, - LAYERTYPE_GAME, // not used + LAYERTYPE_GAME, LAYERTYPE_TILES, LAYERTYPE_QUADS, @@ -90,6 +90,15 @@ unsigned char m_Reserved; }; +struct CMapItemInfo +{ + int m_Version; + int m_Author; + int m_MapVersion; + int m_Credits; + int m_License; +} ; + struct CMapItemImage { int m_Version; @@ -178,7 +187,7 @@ bool operator<(const CEnvPoint &Other) { return m_Time < Other.m_Time; } } ; -struct CMapItemEnvelope +struct CMapItemEnvelope_v1 { int m_Version; int m_Channels; @@ -187,4 +196,10 @@ int m_aName[8]; } ; +struct CMapItemEnvelope : public CMapItemEnvelope_v1 +{ + enum { CURRENT_VERSION=2 }; + int m_Synchronized; +}; + #endif diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/character.cpp teeworlds-0.6.2+dfsg/src/game/server/entities/character.cpp --- teeworlds-0.6.1+dfsg/src/game/server/entities/character.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/character.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -56,6 +56,7 @@ { m_EmoteStop = -1; m_LastAction = -1; + m_LastNoAmmoSound = -1; m_ActiveWeapon = WEAPON_GUN; m_LastWeapon = WEAPON_HAMMER; m_QueuedWeapon = -1; @@ -270,7 +271,11 @@ { // 125ms is a magical limit of how fast a human can click m_ReloadTimer = 125 * Server()->TickSpeed() / 1000; - GameServer()->CreateSound(m_Pos, SOUND_WEAPON_NOAMMO); + if(m_LastNoAmmoSound+Server()->TickSpeed() <= Server()->Tick()) + { + GameServer()->CreateSound(m_Pos, SOUND_WEAPON_NOAMMO); + m_LastNoAmmoSound = Server()->Tick(); + } return; } @@ -507,7 +512,7 @@ mem_copy(&m_Input, pNewInput, sizeof(m_Input)); m_NumInputs++; - // or are not allowed to aim in the center + // it is not allowed to aim in the center if(m_Input.m_TargetX == 0 && m_Input.m_TargetY == 0) m_Input.m_TargetY = -1; } @@ -517,6 +522,10 @@ mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput)); mem_copy(&m_LatestInput, pNewInput, sizeof(m_LatestInput)); + // it is not allowed to aim in the center + if(m_LatestInput.m_TargetX == 0 && m_LatestInput.m_TargetY == 0) + m_LatestInput.m_TargetY = -1; + if(m_NumInputs > 2 && m_pPlayer->GetTeam() != TEAM_SPECTATORS) { HandleWeaponSwitch(); @@ -653,6 +662,20 @@ } } +void CCharacter::TickPaused() +{ + ++m_AttackTick; + ++m_DamageTakenTick; + ++m_Ninja.m_ActivationTick; + ++m_ReckoningTick; + if(m_LastAction != -1) + ++m_LastAction; + if(m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart > -1) + ++m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart; + if(m_EmoteStop > -1) + ++m_EmoteStop; +} + bool CCharacter::IncreaseHealth(int Amount) { if(m_Health >= 10) diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/character.h teeworlds-0.6.2+dfsg/src/game/server/entities/character.h --- teeworlds-0.6.1+dfsg/src/game/server/entities/character.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/character.h 2013-05-01 11:47:39.000000000 +0000 @@ -30,6 +30,7 @@ virtual void Destroy(); virtual void Tick(); virtual void TickDefered(); + virtual void TickPaused(); virtual void Snap(int SnappingClient); bool IsGrounded(); @@ -96,6 +97,7 @@ // last tick that the player took any action ie some input int m_LastAction; + int m_LastNoAmmoSound; // these are non-heldback inputs CNetObj_PlayerInput m_LatestPrevInput; diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/flag.cpp teeworlds-0.6.2+dfsg/src/game/server/entities/flag.cpp --- teeworlds-0.6.1+dfsg/src/game/server/entities/flag.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/flag.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -23,6 +23,13 @@ m_GrabTick = 0; } +void CFlag::TickPaused() +{ + ++m_DropTick; + if(m_GrabTick) + ++m_GrabTick; +} + void CFlag::Snap(int SnappingClient) { if(NetworkClipped(SnappingClient)) diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/flag.h teeworlds-0.6.2+dfsg/src/game/server/entities/flag.h --- teeworlds-0.6.1+dfsg/src/game/server/entities/flag.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/flag.h 2013-05-01 11:47:39.000000000 +0000 @@ -21,6 +21,7 @@ CFlag(CGameWorld *pGameWorld, int Team); virtual void Reset(); + virtual void TickPaused(); virtual void Snap(int SnappingClient); }; diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/laser.cpp teeworlds-0.6.2+dfsg/src/game/server/entities/laser.cpp --- teeworlds-0.6.1+dfsg/src/game/server/entities/laser.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/laser.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -21,15 +21,15 @@ bool CLaser::HitCharacter(vec2 From, vec2 To) { vec2 At; - CCharacter *OwnerChar = GameServer()->GetPlayerChar(m_Owner); - CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, OwnerChar); - if(!Hit) + CCharacter *pOwnerChar = GameServer()->GetPlayerChar(m_Owner); + CCharacter *pHit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, pOwnerChar); + if(!pHit) return false; m_From = From; m_Pos = At; m_Energy = -1; - Hit->TakeDamage(vec2(0.f, 0.f), GameServer()->Tuning()->m_LaserDamage, m_Owner, WEAPON_RIFLE); + pHit->TakeDamage(vec2(0.f, 0.f), GameServer()->Tuning()->m_LaserDamage, m_Owner, WEAPON_RIFLE); return true; } @@ -91,6 +91,11 @@ DoBounce(); } +void CLaser::TickPaused() +{ + ++m_EvalTick; +} + void CLaser::Snap(int SnappingClient) { if(NetworkClipped(SnappingClient)) diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/laser.h teeworlds-0.6.2+dfsg/src/game/server/entities/laser.h --- teeworlds-0.6.1+dfsg/src/game/server/entities/laser.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/laser.h 2013-05-01 11:47:39.000000000 +0000 @@ -12,6 +12,7 @@ virtual void Reset(); virtual void Tick(); + virtual void TickPaused(); virtual void Snap(int SnappingClient); protected: diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/pickup.cpp teeworlds-0.6.2+dfsg/src/game/server/entities/pickup.cpp --- teeworlds-0.6.1+dfsg/src/game/server/entities/pickup.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/pickup.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -117,6 +117,12 @@ } } +void CPickup::TickPaused() +{ + if(m_SpawnTick != -1) + ++m_SpawnTick; +} + void CPickup::Snap(int SnappingClient) { if(m_SpawnTick != -1 || NetworkClipped(SnappingClient)) diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/pickup.h teeworlds-0.6.2+dfsg/src/game/server/entities/pickup.h --- teeworlds-0.6.1+dfsg/src/game/server/entities/pickup.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/pickup.h 2013-05-01 11:47:39.000000000 +0000 @@ -14,6 +14,7 @@ virtual void Reset(); virtual void Tick(); + virtual void TickPaused(); virtual void Snap(int SnappingClient); private: diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/projectile.cpp teeworlds-0.6.2+dfsg/src/game/server/entities/projectile.cpp --- teeworlds-0.6.1+dfsg/src/game/server/entities/projectile.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/projectile.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -82,6 +82,11 @@ } } +void CProjectile::TickPaused() +{ + ++m_StartTick; +} + void CProjectile::FillInfo(CNetObj_Projectile *pProj) { pProj->m_X = (int)m_Pos.x; diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entities/projectile.h teeworlds-0.6.2+dfsg/src/game/server/entities/projectile.h --- teeworlds-0.6.1+dfsg/src/game/server/entities/projectile.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entities/projectile.h 2013-05-01 11:47:39.000000000 +0000 @@ -14,6 +14,7 @@ virtual void Reset(); virtual void Tick(); + virtual void TickPaused(); virtual void Snap(int SnappingClient); private: diff -Nru teeworlds-0.6.1+dfsg/src/game/server/entity.h teeworlds-0.6.2+dfsg/src/game/server/entity.h --- teeworlds-0.6.1+dfsg/src/game/server/entity.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/entity.h 2013-05-01 11:47:39.000000000 +0000 @@ -106,6 +106,12 @@ virtual void TickDefered() {} /* + Function: TickPaused + Called when the game is paused, to freeze the state and position of the entity. + */ + virtual void TickPaused() {} + + /* Function: snap Called when a new snapshot is being generated for a specific client. diff -Nru teeworlds-0.6.1+dfsg/src/game/server/gamecontext.cpp teeworlds-0.6.2+dfsg/src/game/server/gamecontext.cpp --- teeworlds-0.6.1+dfsg/src/game/server/gamecontext.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/gamecontext.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -33,6 +33,7 @@ m_pVoteOptionFirst = 0; m_pVoteOptionLast = 0; m_NumVoteOptions = 0; + m_LockTeams = 0; if(Resetting==NO_RESET) m_pVoteOptionHeap = new CHeap(); @@ -204,7 +205,15 @@ CNetMsg_Sv_SoundGlobal Msg; Msg.m_SoundID = Sound; - Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, Target); + if(Target == -2) + Server()->SendPackMsg(&Msg, MSGFLAG_NOSEND, -1); + else + { + int Flag = MSGFLAG_VITAL; + if(Target != -1) + Flag |= MSGFLAG_NORECORD; + Server()->SendPackMsg(&Msg, Flag, Target); + } } @@ -379,6 +388,22 @@ Server()->SendMsg(&Msg, MSGFLAG_VITAL, ClientID); } +void CGameContext::SwapTeams() +{ + if(!m_pController->IsTeamplay()) + return; + + SendChat(-1, CGameContext::CHAT_ALL, "Teams were swapped"); + + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(m_apPlayers[i] && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) + m_apPlayers[i]->SetTeam(m_apPlayers[i]->GetTeam()^1, false); + } + + (void)m_pController->CheckTeamBalance(); +} + void CGameContext::OnTick() { // check tuning @@ -457,7 +482,9 @@ if(m_VoteEnforce == VOTE_ENFORCE_YES) { + Server()->SetRconCID(IServer::RCON_CID_VOTE); Console()->ExecuteLine(m_aVoteCommand); + Server()->SetRconCID(IServer::RCON_CID_SERV); EndVote(); SendChat(-1, CGameContext::CHAT_ALL, "Vote passed"); @@ -572,396 +599,429 @@ if(!pRawMsg) { - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgID), MsgID, m_NetObjHandler.FailedMsgOn()); - Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); + if(g_Config.m_Debug) + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgID), MsgID, m_NetObjHandler.FailedMsgOn()); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); + } return; } - if(MsgID == NETMSGTYPE_CL_SAY) + if(Server()->ClientIngame(ClientID)) { - CNetMsg_Cl_Say *pMsg = (CNetMsg_Cl_Say *)pRawMsg; - int Team = pMsg->m_Team; - if(Team) - Team = pPlayer->GetTeam(); - else - Team = CGameContext::CHAT_ALL; - - if(g_Config.m_SvSpamprotection && pPlayer->m_LastChat && pPlayer->m_LastChat+Server()->TickSpeed() > Server()->Tick()) - return; + if(MsgID == NETMSGTYPE_CL_SAY) + { + if(g_Config.m_SvSpamprotection && pPlayer->m_LastChat && pPlayer->m_LastChat+Server()->TickSpeed() > Server()->Tick()) + return; - pPlayer->m_LastChat = Server()->Tick(); + CNetMsg_Cl_Say *pMsg = (CNetMsg_Cl_Say *)pRawMsg; + int Team = pMsg->m_Team ? pPlayer->GetTeam() : CGameContext::CHAT_ALL; + + // trim right and set maximum length to 128 utf8-characters + int Length = 0; + const char *p = pMsg->m_pMessage; + const char *pEnd = 0; + while(*p) + { + const char *pStrOld = p; + int Code = str_utf8_decode(&p); + + // check if unicode is not empty + if(Code > 0x20 && Code != 0xA0 && Code != 0x034F && (Code < 0x2000 || Code > 0x200F) && (Code < 0x2028 || Code > 0x202F) && + (Code < 0x205F || Code > 0x2064) && (Code < 0x206A || Code > 0x206F) && (Code < 0xFE00 || Code > 0xFE0F) && + Code != 0xFEFF && (Code < 0xFFF9 || Code > 0xFFFC)) + { + pEnd = 0; + } + else if(pEnd == 0) + pEnd = pStrOld; - // check for invalid chars - unsigned char *pMessage = (unsigned char *)pMsg->m_pMessage; - while (*pMessage) - { - if(*pMessage < 32) - *pMessage = ' '; - pMessage++; - } + if(++Length >= 127) + { + *(const_cast(p)) = 0; + break; + } + } + if(pEnd != 0) + *(const_cast(pEnd)) = 0; - SendChat(ClientID, Team, pMsg->m_pMessage); - } - else if(MsgID == NETMSGTYPE_CL_CALLVOTE) - { - if(g_Config.m_SvSpamprotection && pPlayer->m_LastVoteTry && pPlayer->m_LastVoteTry+Server()->TickSpeed()*3 > Server()->Tick()) - return; + // drop empty and autocreated spam messages (more than 16 characters per second) + if(Length == 0 || (g_Config.m_SvSpamprotection && pPlayer->m_LastChat && pPlayer->m_LastChat+Server()->TickSpeed()*((15+Length)/16) > Server()->Tick())) + return; - int64 Now = Server()->Tick(); - pPlayer->m_LastVoteTry = Now; - if(pPlayer->GetTeam() == TEAM_SPECTATORS) - { - SendChatTarget(ClientID, "Spectators aren't allowed to start a vote."); - return; - } + pPlayer->m_LastChat = Server()->Tick(); - if(m_VoteCloseTime) - { - SendChatTarget(ClientID, "Wait for current vote to end before calling a new one."); - return; + SendChat(ClientID, Team, pMsg->m_pMessage); } - - int Timeleft = pPlayer->m_LastVoteCall + Server()->TickSpeed()*60 - Now; - if(pPlayer->m_LastVoteCall && Timeleft > 0) + else if(MsgID == NETMSGTYPE_CL_CALLVOTE) { - char aChatmsg[512] = {0}; - str_format(aChatmsg, sizeof(aChatmsg), "You must wait %d seconds before making another vote", (Timeleft/Server()->TickSpeed())+1); - SendChatTarget(ClientID, aChatmsg); - return; - } - - char aChatmsg[512] = {0}; - char aDesc[VOTE_DESC_LENGTH] = {0}; - char aCmd[VOTE_CMD_LENGTH] = {0}; - CNetMsg_Cl_CallVote *pMsg = (CNetMsg_Cl_CallVote *)pRawMsg; - const char *pReason = pMsg->m_Reason[0] ? pMsg->m_Reason : "No reason given"; + if(g_Config.m_SvSpamprotection && pPlayer->m_LastVoteTry && pPlayer->m_LastVoteTry+Server()->TickSpeed()*3 > Server()->Tick()) + return; - if(str_comp_nocase(pMsg->m_Type, "option") == 0) - { - CVoteOptionServer *pOption = m_pVoteOptionFirst; - while(pOption) + int64 Now = Server()->Tick(); + pPlayer->m_LastVoteTry = Now; + if(pPlayer->GetTeam() == TEAM_SPECTATORS) { - if(str_comp_nocase(pMsg->m_Value, pOption->m_aDescription) == 0) - { - str_format(aChatmsg, sizeof(aChatmsg), "'%s' called vote to change server option '%s' (%s)", Server()->ClientName(ClientID), - pOption->m_aDescription, pReason); - str_format(aDesc, sizeof(aDesc), "%s", pOption->m_aDescription); - str_format(aCmd, sizeof(aCmd), "%s", pOption->m_aCommand); - break; - } - - pOption = pOption->m_pNext; + SendChatTarget(ClientID, "Spectators aren't allowed to start a vote."); + return; } - if(!pOption) + if(m_VoteCloseTime) { - str_format(aChatmsg, sizeof(aChatmsg), "'%s' isn't an option on this server", pMsg->m_Value); - SendChatTarget(ClientID, aChatmsg); + SendChatTarget(ClientID, "Wait for current vote to end before calling a new one."); return; } - } - else if(str_comp_nocase(pMsg->m_Type, "kick") == 0) - { - if(!g_Config.m_SvVoteKick) + + int Timeleft = pPlayer->m_LastVoteCall + Server()->TickSpeed()*60 - Now; + if(pPlayer->m_LastVoteCall && Timeleft > 0) { - SendChatTarget(ClientID, "Server does not allow voting to kick players"); + char aChatmsg[512] = {0}; + str_format(aChatmsg, sizeof(aChatmsg), "You must wait %d seconds before making another vote", (Timeleft/Server()->TickSpeed())+1); + SendChatTarget(ClientID, aChatmsg); return; } - if(g_Config.m_SvVoteKickMin) + char aChatmsg[512] = {0}; + char aDesc[VOTE_DESC_LENGTH] = {0}; + char aCmd[VOTE_CMD_LENGTH] = {0}; + CNetMsg_Cl_CallVote *pMsg = (CNetMsg_Cl_CallVote *)pRawMsg; + const char *pReason = pMsg->m_Reason[0] ? pMsg->m_Reason : "No reason given"; + + if(str_comp_nocase(pMsg->m_Type, "option") == 0) { - int PlayerNum = 0; - for(int i = 0; i < MAX_CLIENTS; ++i) - if(m_apPlayers[i] && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) - ++PlayerNum; + CVoteOptionServer *pOption = m_pVoteOptionFirst; + while(pOption) + { + if(str_comp_nocase(pMsg->m_Value, pOption->m_aDescription) == 0) + { + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called vote to change server option '%s' (%s)", Server()->ClientName(ClientID), + pOption->m_aDescription, pReason); + str_format(aDesc, sizeof(aDesc), "%s", pOption->m_aDescription); + str_format(aCmd, sizeof(aCmd), "%s", pOption->m_aCommand); + break; + } - if(PlayerNum < g_Config.m_SvVoteKickMin) + pOption = pOption->m_pNext; + } + + if(!pOption) { - str_format(aChatmsg, sizeof(aChatmsg), "Kick voting requires %d players on the server", g_Config.m_SvVoteKickMin); + str_format(aChatmsg, sizeof(aChatmsg), "'%s' isn't an option on this server", pMsg->m_Value); SendChatTarget(ClientID, aChatmsg); return; } } - - int KickID = str_toint(pMsg->m_Value); - if(KickID < 0 || KickID >= MAX_CLIENTS || !m_apPlayers[KickID]) + else if(str_comp_nocase(pMsg->m_Type, "kick") == 0) { - SendChatTarget(ClientID, "Invalid client id to kick"); - return; + if(!g_Config.m_SvVoteKick) + { + SendChatTarget(ClientID, "Server does not allow voting to kick players"); + return; + } + + if(g_Config.m_SvVoteKickMin) + { + int PlayerNum = 0; + for(int i = 0; i < MAX_CLIENTS; ++i) + if(m_apPlayers[i] && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) + ++PlayerNum; + + if(PlayerNum < g_Config.m_SvVoteKickMin) + { + str_format(aChatmsg, sizeof(aChatmsg), "Kick voting requires %d players on the server", g_Config.m_SvVoteKickMin); + SendChatTarget(ClientID, aChatmsg); + return; + } + } + + int KickID = str_toint(pMsg->m_Value); + if(KickID < 0 || KickID >= MAX_CLIENTS || !m_apPlayers[KickID]) + { + SendChatTarget(ClientID, "Invalid client id to kick"); + return; + } + if(KickID == ClientID) + { + SendChatTarget(ClientID, "You can't kick yourself"); + return; + } + if(Server()->IsAuthed(KickID)) + { + SendChatTarget(ClientID, "You can't kick admins"); + char aBufKick[128]; + str_format(aBufKick, sizeof(aBufKick), "'%s' called for vote to kick you", Server()->ClientName(ClientID)); + SendChatTarget(KickID, aBufKick); + return; + } + + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to kick '%s' (%s)", Server()->ClientName(ClientID), Server()->ClientName(KickID), pReason); + str_format(aDesc, sizeof(aDesc), "Kick '%s'", Server()->ClientName(KickID)); + if (!g_Config.m_SvVoteKickBantime) + str_format(aCmd, sizeof(aCmd), "kick %d Kicked by vote", KickID); + else + { + char aAddrStr[NETADDR_MAXSTRSIZE] = {0}; + Server()->GetClientAddr(KickID, aAddrStr, sizeof(aAddrStr)); + str_format(aCmd, sizeof(aCmd), "ban %s %d Banned by vote", aAddrStr, g_Config.m_SvVoteKickBantime); + } } - if(KickID == ClientID) + else if(str_comp_nocase(pMsg->m_Type, "spectate") == 0) { - SendChatTarget(ClientID, "You can't kick yourself"); - return; + if(!g_Config.m_SvVoteSpectate) + { + SendChatTarget(ClientID, "Server does not allow voting to move players to spectators"); + return; + } + + int SpectateID = str_toint(pMsg->m_Value); + if(SpectateID < 0 || SpectateID >= MAX_CLIENTS || !m_apPlayers[SpectateID] || m_apPlayers[SpectateID]->GetTeam() == TEAM_SPECTATORS) + { + SendChatTarget(ClientID, "Invalid client id to move"); + return; + } + if(SpectateID == ClientID) + { + SendChatTarget(ClientID, "You can't move yourself"); + return; + } + + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to move '%s' to spectators (%s)", Server()->ClientName(ClientID), Server()->ClientName(SpectateID), pReason); + str_format(aDesc, sizeof(aDesc), "move '%s' to spectators", Server()->ClientName(SpectateID)); + str_format(aCmd, sizeof(aCmd), "set_team %d -1 %d", SpectateID, g_Config.m_SvVoteSpectateRejoindelay); } - if(Server()->IsAuthed(KickID)) + + if(aCmd[0]) { - SendChatTarget(ClientID, "You can't kick admins"); - char aBufKick[128]; - str_format(aBufKick, sizeof(aBufKick), "'%s' called for vote to kick you", Server()->ClientName(ClientID)); - SendChatTarget(KickID, aBufKick); - return; + SendChat(-1, CGameContext::CHAT_ALL, aChatmsg); + StartVote(aDesc, aCmd, pReason); + pPlayer->m_Vote = 1; + pPlayer->m_VotePos = m_VotePos = 1; + m_VoteCreator = ClientID; + pPlayer->m_LastVoteCall = Now; } + } + else if(MsgID == NETMSGTYPE_CL_VOTE) + { + if(!m_VoteCloseTime) + return; - str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to kick '%s' (%s)", Server()->ClientName(ClientID), Server()->ClientName(KickID), pReason); - str_format(aDesc, sizeof(aDesc), "Kick '%s'", Server()->ClientName(KickID)); - if (!g_Config.m_SvVoteKickBantime) - str_format(aCmd, sizeof(aCmd), "kick %d Kicked by vote", KickID); - else + if(pPlayer->m_Vote == 0) { - char aAddrStr[NETADDR_MAXSTRSIZE] = {0}; - Server()->GetClientAddr(KickID, aAddrStr, sizeof(aAddrStr)); - str_format(aCmd, sizeof(aCmd), "ban %s %d Banned by vote", aAddrStr, g_Config.m_SvVoteKickBantime); - Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aCmd); + CNetMsg_Cl_Vote *pMsg = (CNetMsg_Cl_Vote *)pRawMsg; + if(!pMsg->m_Vote) + return; + + pPlayer->m_Vote = pMsg->m_Vote; + pPlayer->m_VotePos = ++m_VotePos; + m_VoteUpdate = true; } } - else if(str_comp_nocase(pMsg->m_Type, "spectate") == 0) + else if (MsgID == NETMSGTYPE_CL_SETTEAM && !m_World.m_Paused) { - if(!g_Config.m_SvVoteSpectate) - { - SendChatTarget(ClientID, "Server does not allow voting to move players to spectators"); + CNetMsg_Cl_SetTeam *pMsg = (CNetMsg_Cl_SetTeam *)pRawMsg; + + if(pPlayer->GetTeam() == pMsg->m_Team || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetTeam && pPlayer->m_LastSetTeam+Server()->TickSpeed()*3 > Server()->Tick())) return; - } - int SpectateID = str_toint(pMsg->m_Value); - if(SpectateID < 0 || SpectateID >= MAX_CLIENTS || !m_apPlayers[SpectateID] || m_apPlayers[SpectateID]->GetTeam() == TEAM_SPECTATORS) + if(pMsg->m_Team != TEAM_SPECTATORS && m_LockTeams) { - SendChatTarget(ClientID, "Invalid client id to move"); + pPlayer->m_LastSetTeam = Server()->Tick(); + SendBroadcast("Teams are locked", ClientID); return; } - if(SpectateID == ClientID) + + if(pPlayer->m_TeamChangeTick > Server()->Tick()) { - SendChatTarget(ClientID, "You can't move yourself"); + pPlayer->m_LastSetTeam = Server()->Tick(); + int TimeLeft = (pPlayer->m_TeamChangeTick - Server()->Tick())/Server()->TickSpeed(); + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "Time to wait before changing team: %02d:%02d", TimeLeft/60, TimeLeft%60); + SendBroadcast(aBuf, ClientID); return; } - str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to move '%s' to spectators (%s)", Server()->ClientName(ClientID), Server()->ClientName(SpectateID), pReason); - str_format(aDesc, sizeof(aDesc), "move '%s' to spectators", Server()->ClientName(SpectateID)); - str_format(aCmd, sizeof(aCmd), "set_team %d -1 %d", SpectateID, g_Config.m_SvVoteSpectateRejoindelay); + // Switch team on given client and kill/respawn him + if(m_pController->CanJoinTeam(pMsg->m_Team, ClientID)) + { + if(m_pController->CanChangeTeam(pPlayer, pMsg->m_Team)) + { + pPlayer->m_LastSetTeam = Server()->Tick(); + if(pPlayer->GetTeam() == TEAM_SPECTATORS || pMsg->m_Team == TEAM_SPECTATORS) + m_VoteUpdate = true; + pPlayer->SetTeam(pMsg->m_Team); + (void)m_pController->CheckTeamBalance(); + pPlayer->m_TeamChangeTick = Server()->Tick(); + } + else + SendBroadcast("Teams must be balanced, please join other team", ClientID); + } + else + { + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "Only %d active players are allowed", Server()->MaxClients()-g_Config.m_SvSpectatorSlots); + SendBroadcast(aBuf, ClientID); + } } - - if(aCmd[0]) + else if (MsgID == NETMSGTYPE_CL_SETSPECTATORMODE && !m_World.m_Paused) { - SendChat(-1, CGameContext::CHAT_ALL, aChatmsg); - StartVote(aDesc, aCmd, pReason); - pPlayer->m_Vote = 1; - pPlayer->m_VotePos = m_VotePos = 1; - m_VoteCreator = ClientID; - pPlayer->m_LastVoteCall = Now; - } - } - else if(MsgID == NETMSGTYPE_CL_VOTE) - { - if(!m_VoteCloseTime) - return; + CNetMsg_Cl_SetSpectatorMode *pMsg = (CNetMsg_Cl_SetSpectatorMode *)pRawMsg; - if(pPlayer->m_Vote == 0) - { - CNetMsg_Cl_Vote *pMsg = (CNetMsg_Cl_Vote *)pRawMsg; - if(!pMsg->m_Vote) + if(pPlayer->GetTeam() != TEAM_SPECTATORS || pPlayer->m_SpectatorID == pMsg->m_SpectatorID || ClientID == pMsg->m_SpectatorID || + (g_Config.m_SvSpamprotection && pPlayer->m_LastSetSpectatorMode && pPlayer->m_LastSetSpectatorMode+Server()->TickSpeed()*3 > Server()->Tick())) return; - pPlayer->m_Vote = pMsg->m_Vote; - pPlayer->m_VotePos = ++m_VotePos; - m_VoteUpdate = true; + pPlayer->m_LastSetSpectatorMode = Server()->Tick(); + if(pMsg->m_SpectatorID != SPEC_FREEVIEW && (!m_apPlayers[pMsg->m_SpectatorID] || m_apPlayers[pMsg->m_SpectatorID]->GetTeam() == TEAM_SPECTATORS)) + SendChatTarget(ClientID, "Invalid spectator id used"); + else + pPlayer->m_SpectatorID = pMsg->m_SpectatorID; } - } - else if (MsgID == NETMSGTYPE_CL_SETTEAM && !m_World.m_Paused) - { - CNetMsg_Cl_SetTeam *pMsg = (CNetMsg_Cl_SetTeam *)pRawMsg; - - if(pPlayer->GetTeam() == pMsg->m_Team || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetTeam && pPlayer->m_LastSetTeam+Server()->TickSpeed()*3 > Server()->Tick())) - return; - - if(pPlayer->m_TeamChangeTick > Server()->Tick()) + else if (MsgID == NETMSGTYPE_CL_CHANGEINFO) { - pPlayer->m_LastSetTeam = Server()->Tick(); - int TimeLeft = (pPlayer->m_TeamChangeTick - Server()->Tick())/Server()->TickSpeed(); - char aBuf[128]; - str_format(aBuf, sizeof(aBuf), "Time to wait before changing team: %02d:%02d", TimeLeft/60, TimeLeft%60); - SendBroadcast(aBuf, ClientID); - return; - } + if(g_Config.m_SvSpamprotection && pPlayer->m_LastChangeInfo && pPlayer->m_LastChangeInfo+Server()->TickSpeed()*5 > Server()->Tick()) + return; - // Switch team on given client and kill/respawn him - if(m_pController->CanJoinTeam(pMsg->m_Team, ClientID)) - { - if(m_pController->CanChangeTeam(pPlayer, pMsg->m_Team)) + CNetMsg_Cl_ChangeInfo *pMsg = (CNetMsg_Cl_ChangeInfo *)pRawMsg; + pPlayer->m_LastChangeInfo = Server()->Tick(); + + // set infos + char aOldName[MAX_NAME_LENGTH]; + str_copy(aOldName, Server()->ClientName(ClientID), sizeof(aOldName)); + Server()->SetClientName(ClientID, pMsg->m_pName); + if(str_comp(aOldName, Server()->ClientName(ClientID)) != 0) { - pPlayer->m_LastSetTeam = Server()->Tick(); - if(pPlayer->GetTeam() == TEAM_SPECTATORS || pMsg->m_Team == TEAM_SPECTATORS) - m_VoteUpdate = true; - pPlayer->SetTeam(pMsg->m_Team); - (void)m_pController->CheckTeamBalance(); - pPlayer->m_TeamChangeTick = Server()->Tick(); + char aChatText[256]; + str_format(aChatText, sizeof(aChatText), "'%s' changed name to '%s'", aOldName, Server()->ClientName(ClientID)); + SendChat(-1, CGameContext::CHAT_ALL, aChatText); } - else - SendBroadcast("Teams must be balanced, please join other team", ClientID); + Server()->SetClientClan(ClientID, pMsg->m_pClan); + Server()->SetClientCountry(ClientID, pMsg->m_Country); + str_copy(pPlayer->m_TeeInfos.m_SkinName, pMsg->m_pSkin, sizeof(pPlayer->m_TeeInfos.m_SkinName)); + pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor; + pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody; + pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet; + m_pController->OnPlayerInfoChange(pPlayer); } - else + else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) { - char aBuf[128]; - str_format(aBuf, sizeof(aBuf), "Only %d active players are allowed", g_Config.m_SvMaxClients-g_Config.m_SvSpectatorSlots); - SendBroadcast(aBuf, ClientID); - } - } - else if (MsgID == NETMSGTYPE_CL_SETSPECTATORMODE && !m_World.m_Paused) - { - CNetMsg_Cl_SetSpectatorMode *pMsg = (CNetMsg_Cl_SetSpectatorMode *)pRawMsg; - - if(pPlayer->GetTeam() != TEAM_SPECTATORS || pPlayer->m_SpectatorID == pMsg->m_SpectatorID || ClientID == pMsg->m_SpectatorID || - (g_Config.m_SvSpamprotection && pPlayer->m_LastSetSpectatorMode && pPlayer->m_LastSetSpectatorMode+Server()->TickSpeed()*3 > Server()->Tick())) - return; + CNetMsg_Cl_Emoticon *pMsg = (CNetMsg_Cl_Emoticon *)pRawMsg; - pPlayer->m_LastSetSpectatorMode = Server()->Tick(); - if(pMsg->m_SpectatorID != SPEC_FREEVIEW && (!m_apPlayers[pMsg->m_SpectatorID] || m_apPlayers[pMsg->m_SpectatorID]->GetTeam() == TEAM_SPECTATORS)) - SendChatTarget(ClientID, "Invalid spectator id used"); - else - pPlayer->m_SpectatorID = pMsg->m_SpectatorID; - } - else if (MsgID == NETMSGTYPE_CL_STARTINFO) - { - if(pPlayer->m_IsReady) - return; + if(g_Config.m_SvSpamprotection && pPlayer->m_LastEmote && pPlayer->m_LastEmote+Server()->TickSpeed()*3 > Server()->Tick()) + return; - CNetMsg_Cl_StartInfo *pMsg = (CNetMsg_Cl_StartInfo *)pRawMsg; - pPlayer->m_LastChangeInfo = Server()->Tick(); + pPlayer->m_LastEmote = Server()->Tick(); - // set start infos - Server()->SetClientName(ClientID, pMsg->m_pName); - Server()->SetClientClan(ClientID, pMsg->m_pClan); - Server()->SetClientCountry(ClientID, pMsg->m_Country); - str_copy(pPlayer->m_TeeInfos.m_SkinName, pMsg->m_pSkin, sizeof(pPlayer->m_TeeInfos.m_SkinName)); - pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor; - pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody; - pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet; - m_pController->OnPlayerInfoChange(pPlayer); - - // send vote options - CNetMsg_Sv_VoteClearOptions ClearMsg; - Server()->SendPackMsg(&ClearMsg, MSGFLAG_VITAL, ClientID); - - CNetMsg_Sv_VoteOptionListAdd OptionMsg; - int NumOptions = 0; - OptionMsg.m_pDescription0 = ""; - OptionMsg.m_pDescription1 = ""; - OptionMsg.m_pDescription2 = ""; - OptionMsg.m_pDescription3 = ""; - OptionMsg.m_pDescription4 = ""; - OptionMsg.m_pDescription5 = ""; - OptionMsg.m_pDescription6 = ""; - OptionMsg.m_pDescription7 = ""; - OptionMsg.m_pDescription8 = ""; - OptionMsg.m_pDescription9 = ""; - OptionMsg.m_pDescription10 = ""; - OptionMsg.m_pDescription11 = ""; - OptionMsg.m_pDescription12 = ""; - OptionMsg.m_pDescription13 = ""; - OptionMsg.m_pDescription14 = ""; - CVoteOptionServer *pCurrent = m_pVoteOptionFirst; - while(pCurrent) - { - switch(NumOptions++) - { - case 0: OptionMsg.m_pDescription0 = pCurrent->m_aDescription; break; - case 1: OptionMsg.m_pDescription1 = pCurrent->m_aDescription; break; - case 2: OptionMsg.m_pDescription2 = pCurrent->m_aDescription; break; - case 3: OptionMsg.m_pDescription3 = pCurrent->m_aDescription; break; - case 4: OptionMsg.m_pDescription4 = pCurrent->m_aDescription; break; - case 5: OptionMsg.m_pDescription5 = pCurrent->m_aDescription; break; - case 6: OptionMsg.m_pDescription6 = pCurrent->m_aDescription; break; - case 7: OptionMsg.m_pDescription7 = pCurrent->m_aDescription; break; - case 8: OptionMsg.m_pDescription8 = pCurrent->m_aDescription; break; - case 9: OptionMsg.m_pDescription9 = pCurrent->m_aDescription; break; - case 10: OptionMsg.m_pDescription10 = pCurrent->m_aDescription; break; - case 11: OptionMsg.m_pDescription11 = pCurrent->m_aDescription; break; - case 12: OptionMsg.m_pDescription12 = pCurrent->m_aDescription; break; - case 13: OptionMsg.m_pDescription13 = pCurrent->m_aDescription; break; - case 14: - { - OptionMsg.m_pDescription14 = pCurrent->m_aDescription; - OptionMsg.m_NumOptions = NumOptions; - Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); - OptionMsg = CNetMsg_Sv_VoteOptionListAdd(); - NumOptions = 0; - OptionMsg.m_pDescription1 = ""; - OptionMsg.m_pDescription2 = ""; - OptionMsg.m_pDescription3 = ""; - OptionMsg.m_pDescription4 = ""; - OptionMsg.m_pDescription5 = ""; - OptionMsg.m_pDescription6 = ""; - OptionMsg.m_pDescription7 = ""; - OptionMsg.m_pDescription8 = ""; - OptionMsg.m_pDescription9 = ""; - OptionMsg.m_pDescription10 = ""; - OptionMsg.m_pDescription11 = ""; - OptionMsg.m_pDescription12 = ""; - OptionMsg.m_pDescription13 = ""; - OptionMsg.m_pDescription14 = ""; - } - } - pCurrent = pCurrent->m_pNext; + SendEmoticon(ClientID, pMsg->m_Emoticon); } - if(NumOptions > 0) + else if (MsgID == NETMSGTYPE_CL_KILL && !m_World.m_Paused) { - OptionMsg.m_NumOptions = NumOptions; - Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); - NumOptions = 0; - } - - // send tuning parameters to client - SendTuningParams(ClientID); - - // client is ready to enter - pPlayer->m_IsReady = true; - CNetMsg_Sv_ReadyToEnter m; - Server()->SendPackMsg(&m, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID); - } - else if (MsgID == NETMSGTYPE_CL_CHANGEINFO) - { - if(g_Config.m_SvSpamprotection && pPlayer->m_LastChangeInfo && pPlayer->m_LastChangeInfo+Server()->TickSpeed()*5 > Server()->Tick()) - return; - - CNetMsg_Cl_ChangeInfo *pMsg = (CNetMsg_Cl_ChangeInfo *)pRawMsg; - pPlayer->m_LastChangeInfo = Server()->Tick(); + if(pPlayer->m_LastKill && pPlayer->m_LastKill+Server()->TickSpeed()*3 > Server()->Tick()) + return; - // set infos - char aOldName[MAX_NAME_LENGTH]; - str_copy(aOldName, Server()->ClientName(ClientID), sizeof(aOldName)); - Server()->SetClientName(ClientID, pMsg->m_pName); - if(str_comp(aOldName, Server()->ClientName(ClientID)) != 0) - { - char aChatText[256]; - str_format(aChatText, sizeof(aChatText), "'%s' changed name to '%s'", aOldName, Server()->ClientName(ClientID)); - SendChat(-1, CGameContext::CHAT_ALL, aChatText); - } - Server()->SetClientClan(ClientID, pMsg->m_pClan); - Server()->SetClientCountry(ClientID, pMsg->m_Country); - str_copy(pPlayer->m_TeeInfos.m_SkinName, pMsg->m_pSkin, sizeof(pPlayer->m_TeeInfos.m_SkinName)); - pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor; - pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody; - pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet; - m_pController->OnPlayerInfoChange(pPlayer); + pPlayer->m_LastKill = Server()->Tick(); + pPlayer->KillCharacter(WEAPON_SELF); + } } - else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) + else { - CNetMsg_Cl_Emoticon *pMsg = (CNetMsg_Cl_Emoticon *)pRawMsg; + if(MsgID == NETMSGTYPE_CL_STARTINFO) + { + if(pPlayer->m_IsReady) + return; - if(g_Config.m_SvSpamprotection && pPlayer->m_LastEmote && pPlayer->m_LastEmote+Server()->TickSpeed()*3 > Server()->Tick()) - return; + CNetMsg_Cl_StartInfo *pMsg = (CNetMsg_Cl_StartInfo *)pRawMsg; + pPlayer->m_LastChangeInfo = Server()->Tick(); - pPlayer->m_LastEmote = Server()->Tick(); + // set start infos + Server()->SetClientName(ClientID, pMsg->m_pName); + Server()->SetClientClan(ClientID, pMsg->m_pClan); + Server()->SetClientCountry(ClientID, pMsg->m_Country); + str_copy(pPlayer->m_TeeInfos.m_SkinName, pMsg->m_pSkin, sizeof(pPlayer->m_TeeInfos.m_SkinName)); + pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor; + pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody; + pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet; + m_pController->OnPlayerInfoChange(pPlayer); + + // send vote options + CNetMsg_Sv_VoteClearOptions ClearMsg; + Server()->SendPackMsg(&ClearMsg, MSGFLAG_VITAL, ClientID); + + CNetMsg_Sv_VoteOptionListAdd OptionMsg; + int NumOptions = 0; + OptionMsg.m_pDescription0 = ""; + OptionMsg.m_pDescription1 = ""; + OptionMsg.m_pDescription2 = ""; + OptionMsg.m_pDescription3 = ""; + OptionMsg.m_pDescription4 = ""; + OptionMsg.m_pDescription5 = ""; + OptionMsg.m_pDescription6 = ""; + OptionMsg.m_pDescription7 = ""; + OptionMsg.m_pDescription8 = ""; + OptionMsg.m_pDescription9 = ""; + OptionMsg.m_pDescription10 = ""; + OptionMsg.m_pDescription11 = ""; + OptionMsg.m_pDescription12 = ""; + OptionMsg.m_pDescription13 = ""; + OptionMsg.m_pDescription14 = ""; + CVoteOptionServer *pCurrent = m_pVoteOptionFirst; + while(pCurrent) + { + switch(NumOptions++) + { + case 0: OptionMsg.m_pDescription0 = pCurrent->m_aDescription; break; + case 1: OptionMsg.m_pDescription1 = pCurrent->m_aDescription; break; + case 2: OptionMsg.m_pDescription2 = pCurrent->m_aDescription; break; + case 3: OptionMsg.m_pDescription3 = pCurrent->m_aDescription; break; + case 4: OptionMsg.m_pDescription4 = pCurrent->m_aDescription; break; + case 5: OptionMsg.m_pDescription5 = pCurrent->m_aDescription; break; + case 6: OptionMsg.m_pDescription6 = pCurrent->m_aDescription; break; + case 7: OptionMsg.m_pDescription7 = pCurrent->m_aDescription; break; + case 8: OptionMsg.m_pDescription8 = pCurrent->m_aDescription; break; + case 9: OptionMsg.m_pDescription9 = pCurrent->m_aDescription; break; + case 10: OptionMsg.m_pDescription10 = pCurrent->m_aDescription; break; + case 11: OptionMsg.m_pDescription11 = pCurrent->m_aDescription; break; + case 12: OptionMsg.m_pDescription12 = pCurrent->m_aDescription; break; + case 13: OptionMsg.m_pDescription13 = pCurrent->m_aDescription; break; + case 14: + { + OptionMsg.m_pDescription14 = pCurrent->m_aDescription; + OptionMsg.m_NumOptions = NumOptions; + Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); + OptionMsg = CNetMsg_Sv_VoteOptionListAdd(); + NumOptions = 0; + OptionMsg.m_pDescription1 = ""; + OptionMsg.m_pDescription2 = ""; + OptionMsg.m_pDescription3 = ""; + OptionMsg.m_pDescription4 = ""; + OptionMsg.m_pDescription5 = ""; + OptionMsg.m_pDescription6 = ""; + OptionMsg.m_pDescription7 = ""; + OptionMsg.m_pDescription8 = ""; + OptionMsg.m_pDescription9 = ""; + OptionMsg.m_pDescription10 = ""; + OptionMsg.m_pDescription11 = ""; + OptionMsg.m_pDescription12 = ""; + OptionMsg.m_pDescription13 = ""; + OptionMsg.m_pDescription14 = ""; + } + } + pCurrent = pCurrent->m_pNext; + } + if(NumOptions > 0) + { + OptionMsg.m_NumOptions = NumOptions; + Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); + } - SendEmoticon(ClientID, pMsg->m_Emoticon); - } - else if (MsgID == NETMSGTYPE_CL_KILL && !m_World.m_Paused) - { - if(pPlayer->m_LastKill && pPlayer->m_LastKill+Server()->TickSpeed()*3 > Server()->Tick()) - return; + // send tuning parameters to client + SendTuningParams(ClientID); - pPlayer->m_LastKill = Server()->Tick(); - pPlayer->KillCharacter(WEAPON_SELF); + // client is ready to enter + pPlayer->m_IsReady = true; + CNetMsg_Sv_ReadyToEnter m; + Server()->SendPackMsg(&m, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID); + } } } @@ -1004,6 +1064,16 @@ } } +void CGameContext::ConPause(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + + if(pSelf->m_pController->IsGameOver()) + return; + + pSelf->m_World.m_Paused ^= 1; +} + void CGameContext::ConChangeMap(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; @@ -1036,17 +1106,14 @@ CGameContext *pSelf = (CGameContext *)pUserData; int ClientID = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int Team = clamp(pResult->GetInteger(1), -1, 1); - int Delay = 0; - if(pResult->NumArguments() > 2) - Delay = pResult->GetInteger(2); + int Delay = pResult->NumArguments()>2 ? pResult->GetInteger(2) : 0; + if(!pSelf->m_apPlayers[ClientID]) + return; char aBuf[256]; str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", ClientID, Team); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - if(!pSelf->m_apPlayers[ClientID]) - return; - pSelf->m_apPlayers[ClientID]->m_TeamChangeTick = pSelf->Server()->Tick()+pSelf->Server()->TickSpeed()*Delay*60; pSelf->m_apPlayers[ClientID]->SetTeam(Team); (void)pSelf->m_pController->CheckTeamBalance(); @@ -1058,16 +1125,75 @@ int Team = clamp(pResult->GetInteger(0), -1, 1); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "moved all clients to team %d", Team); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + str_format(aBuf, sizeof(aBuf), "All players were moved to the %s", pSelf->m_pController->GetTeamName(Team)); + pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf); for(int i = 0; i < MAX_CLIENTS; ++i) if(pSelf->m_apPlayers[i]) - pSelf->m_apPlayers[i]->SetTeam(Team); + pSelf->m_apPlayers[i]->SetTeam(Team, false); + + (void)pSelf->m_pController->CheckTeamBalance(); +} + +void CGameContext::ConSwapTeams(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + pSelf->SwapTeams(); +} + +void CGameContext::ConShuffleTeams(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!pSelf->m_pController->IsTeamplay()) + return; + + int CounterRed = 0; + int CounterBlue = 0; + int PlayerTeam = 0; + for(int i = 0; i < MAX_CLIENTS; ++i) + if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) + ++PlayerTeam; + PlayerTeam = (PlayerTeam+1)/2; + + pSelf->SendChat(-1, CGameContext::CHAT_ALL, "Teams were shuffled"); + + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) + { + if(CounterRed == PlayerTeam) + pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE, false); + else if(CounterBlue == PlayerTeam) + pSelf->m_apPlayers[i]->SetTeam(TEAM_RED, false); + else + { + if(rand() % 2) + { + pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE, false); + ++CounterBlue; + } + else + { + pSelf->m_apPlayers[i]->SetTeam(TEAM_RED, false); + ++CounterRed; + } + } + } + } (void)pSelf->m_pController->CheckTeamBalance(); } +void CGameContext::ConLockTeams(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + pSelf->m_LockTeams ^= 1; + if(pSelf->m_LockTeams) + pSelf->SendChat(-1, CGameContext::CHAT_ALL, "Teams were locked"); + else + pSelf->SendChat(-1, CGameContext::CHAT_ALL, "Teams were unlocked"); +} + void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; @@ -1287,6 +1413,11 @@ void CGameContext::ConVote(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; + + // check if there is a vote running + if(!pSelf->m_VoteCloseTime) + return; + if(str_comp_nocase(pResult->GetString(0), "yes") == 0) pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_YES; else if(str_comp_nocase(pResult->GetString(0), "no") == 0) @@ -1321,12 +1452,16 @@ Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "Reset tuning"); Console()->Register("tune_dump", "", CFGFLAG_SERVER, ConTuneDump, this, "Dump tuning"); + Console()->Register("pause", "", CFGFLAG_SERVER, ConPause, this, "Pause/unpause game"); Console()->Register("change_map", "?r", CFGFLAG_SERVER|CFGFLAG_STORE, ConChangeMap, this, "Change map"); - Console()->Register("restart", "?i", CFGFLAG_SERVER|CFGFLAG_STORE, ConRestart, this, "Restart in x seconds"); + Console()->Register("restart", "?i", CFGFLAG_SERVER|CFGFLAG_STORE, ConRestart, this, "Restart in x seconds (0 = abort)"); Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, "Broadcast message"); Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Say in chat"); Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, ConSetTeam, this, "Set team of player to team"); Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, "Set team of all players to team"); + Console()->Register("swap_teams", "", CFGFLAG_SERVER, ConSwapTeams, this, "Swap the current teams"); + Console()->Register("shuffle_teams", "", CFGFLAG_SERVER, ConShuffleTeams, this, "Shuffle the current teams"); + Console()->Register("lock_teams", "", CFGFLAG_SERVER, ConLockTeams, this, "Lock/unlock teams"); Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, "Add a voting option"); Console()->Register("remove_vote", "s", CFGFLAG_SERVER, ConRemoveVote, this, "remove a voting option"); @@ -1420,6 +1555,17 @@ void CGameContext::OnSnap(int ClientID) { + // add tuning to demo + CTuningParams StandardTuning; + if(ClientID == -1 && Server()->DemoRecorder_IsRecording() && mem_comp(&StandardTuning, &m_Tuning, sizeof(CTuningParams)) != 0) + { + CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); + int *pParams = (int *)&m_Tuning; + for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) + Msg.AddInt(pParams[i]); + Server()->SendMsg(&Msg, MSGFLAG_RECORD|MSGFLAG_NOSEND, ClientID); + } + m_World.Snap(ClientID); m_pController->Snap(ClientID); m_Events.Snap(ClientID); diff -Nru teeworlds-0.6.1+dfsg/src/game/server/gamecontext.h teeworlds-0.6.2+dfsg/src/game/server/gamecontext.h --- teeworlds-0.6.1+dfsg/src/game/server/gamecontext.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/gamecontext.h 2013-05-01 11:47:39.000000000 +0000 @@ -48,12 +48,16 @@ static void ConTuneParam(IConsole::IResult *pResult, void *pUserData); static void ConTuneReset(IConsole::IResult *pResult, void *pUserData); static void ConTuneDump(IConsole::IResult *pResult, void *pUserData); + static void ConPause(IConsole::IResult *pResult, void *pUserData); static void ConChangeMap(IConsole::IResult *pResult, void *pUserData); static void ConRestart(IConsole::IResult *pResult, void *pUserData); static void ConBroadcast(IConsole::IResult *pResult, void *pUserData); static void ConSay(IConsole::IResult *pResult, void *pUserData); static void ConSetTeam(IConsole::IResult *pResult, void *pUserData); static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData); + static void ConSwapTeams(IConsole::IResult *pResult, void *pUserData); + static void ConShuffleTeams(IConsole::IResult *pResult, void *pUserData); + static void ConLockTeams(IConsole::IResult *pResult, void *pUserData); static void ConAddVote(IConsole::IResult *pResult, void *pUserData); static void ConRemoveVote(IConsole::IResult *pResult, void *pUserData); static void ConForceVote(IConsole::IResult *pResult, void *pUserData); @@ -85,6 +89,8 @@ // helper functions class CCharacter *GetPlayerChar(int ClientID); + int m_LockTeams; + // voting void StartVote(const char *pDesc, const char *pCommand, const char *pReason); void EndVote(); @@ -141,6 +147,9 @@ void CheckPureTuning(); void SendTuningParams(int ClientID); + // + void SwapTeams(); + // engine events virtual void OnInit(); virtual void OnConsoleInit(); diff -Nru teeworlds-0.6.1+dfsg/src/game/server/gamecontroller.cpp teeworlds-0.6.2+dfsg/src/game/server/gamecontroller.cpp --- teeworlds-0.6.1+dfsg/src/game/server/gamecontroller.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/gamecontroller.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -245,7 +245,11 @@ return; if(m_RoundCount < g_Config.m_SvRoundsPerMap-1) + { + if(g_Config.m_SvRoundSwap) + GameServer()->SwapTeams(); return; + } // handle maprotation const char *pMapRotation = g_Config.m_SvMaprotation; @@ -277,8 +281,8 @@ pNextMap = pMapRotation; // cut out the next map - char aBuf[512]; - for(int i = 0; i < 512; i++) + char aBuf[512] = {0}; + for(int i = 0; i < 511; i++) { aBuf[i] = pNextMap[i]; if(IsSeparator(pNextMap[i]) || pNextMap[i] == 0) @@ -426,8 +430,12 @@ } } + // game is Paused + if(GameServer()->m_World.m_Paused) + ++m_RoundStartTick; + // do team-balancing - if (IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) + if(IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) { GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams"); @@ -486,6 +494,13 @@ { for(int i = 0; i < MAX_CLIENTS; ++i) { + #ifdef CONF_DEBUG + if(g_Config.m_DbgDummies) + { + if(i >= MAX_CLIENTS-g_Config.m_DbgDummies) + break; + } + #endif if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !Server()->IsAuthed(i)) { if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60) @@ -595,7 +610,7 @@ } } - return (aNumplayers[0] + aNumplayers[1]) < g_Config.m_SvMaxClients-g_Config.m_SvSpectatorSlots; + return (aNumplayers[0] + aNumplayers[1]) < Server()->MaxClients()-g_Config.m_SvSpectatorSlots; } bool IGameController::CheckTeamBalance() diff -Nru teeworlds-0.6.1+dfsg/src/game/server/gamecontroller.h teeworlds-0.6.2+dfsg/src/game/server/gamecontroller.h --- teeworlds-0.6.1+dfsg/src/game/server/gamecontroller.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/gamecontroller.h 2013-05-01 11:47:39.000000000 +0000 @@ -64,6 +64,7 @@ const char *m_pGameType; bool IsTeamplay() const; + bool IsGameOver() const { return m_GameOverTick != -1; } IGameController(class CGameContext *pGameServer); virtual ~IGameController(); diff -Nru teeworlds-0.6.1+dfsg/src/game/server/gamemodes/ctf.cpp teeworlds-0.6.2+dfsg/src/game/server/gamemodes/ctf.cpp --- teeworlds-0.6.1+dfsg/src/game/server/gamemodes/ctf.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/gamemodes/ctf.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -98,7 +98,7 @@ for(int fi = 0; fi < 2; fi++) { CFlag *F = m_apFlags[fi]; - if(F->m_pCarryingCharacter == Character) + if(F && F->m_pCarryingCharacter == Character) return false; } } @@ -259,6 +259,8 @@ else GameServer()->CreateSoundGlobal(SOUND_CTF_GRAB_PL, c); } + // demo record entry + GameServer()->CreateSoundGlobal(SOUND_CTF_GRAB_EN, -2); break; } } diff -Nru teeworlds-0.6.1+dfsg/src/game/server/gamemodes/tdm.cpp teeworlds-0.6.2+dfsg/src/game/server/gamemodes/tdm.cpp --- teeworlds-0.6.1+dfsg/src/game/server/gamemodes/tdm.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/gamemodes/tdm.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -17,7 +17,7 @@ IGameController::OnCharacterDeath(pVictim, pKiller, Weapon); - if(Weapon != WEAPON_GAME) + if(pKiller && Weapon != WEAPON_GAME) { // do team scoring if(pKiller == pVictim->GetPlayer() || pKiller->GetTeam() == pVictim->GetPlayer()->GetTeam()) diff -Nru teeworlds-0.6.1+dfsg/src/game/server/gameworld.cpp teeworlds-0.6.2+dfsg/src/game/server/gameworld.cpp --- teeworlds-0.6.1+dfsg/src/game/server/gameworld.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/gameworld.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -173,6 +173,17 @@ pEnt = m_pNextTraverseEntity; } } + else + { + // update all objects + for(int i = 0; i < NUM_ENTTYPES; i++) + for(CEntity *pEnt = m_apFirstEntityTypes[i]; pEnt; ) + { + m_pNextTraverseEntity = pEnt->m_pNextTypeEntity; + pEnt->TickPaused(); + pEnt = m_pNextTraverseEntity; + } + } RemoveEntities(); } diff -Nru teeworlds-0.6.1+dfsg/src/game/server/player.cpp teeworlds-0.6.2+dfsg/src/game/server/player.cpp --- teeworlds-0.6.1+dfsg/src/game/server/player.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/player.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -60,26 +60,37 @@ } } - if(!m_pCharacter && m_Team == TEAM_SPECTATORS && m_SpectatorID == SPEC_FREEVIEW) - m_ViewPos -= vec2(clamp(m_ViewPos.x-m_LatestActivity.m_TargetX, -500.0f, 500.0f), clamp(m_ViewPos.y-m_LatestActivity.m_TargetY, -400.0f, 400.0f)); + if(!GameServer()->m_World.m_Paused) + { + if(!m_pCharacter && m_Team == TEAM_SPECTATORS && m_SpectatorID == SPEC_FREEVIEW) + m_ViewPos -= vec2(clamp(m_ViewPos.x-m_LatestActivity.m_TargetX, -500.0f, 500.0f), clamp(m_ViewPos.y-m_LatestActivity.m_TargetY, -400.0f, 400.0f)); - if(!m_pCharacter && m_DieTick+Server()->TickSpeed()*3 <= Server()->Tick()) - m_Spawning = true; + if(!m_pCharacter && m_DieTick+Server()->TickSpeed()*3 <= Server()->Tick()) + m_Spawning = true; - if(m_pCharacter) - { - if(m_pCharacter->IsAlive()) - { - m_ViewPos = m_pCharacter->m_Pos; - } - else + if(m_pCharacter) { - delete m_pCharacter; - m_pCharacter = 0; + if(m_pCharacter->IsAlive()) + { + m_ViewPos = m_pCharacter->m_Pos; + } + else + { + delete m_pCharacter; + m_pCharacter = 0; + } } + else if(m_Spawning && m_RespawnTick <= Server()->Tick()) + TryRespawn(); } - else if(m_Spawning && m_RespawnTick <= Server()->Tick()) - TryRespawn(); + else + { + ++m_RespawnTick; + ++m_DieTick; + ++m_ScoreStartTick; + ++m_LastActionTick; + ++m_TeamChangeTick; + } } void CPlayer::PostTick() @@ -230,7 +241,7 @@ m_Spawning = true; } -void CPlayer::SetTeam(int Team) +void CPlayer::SetTeam(int Team, bool DoChatMsg) { // clamp the team Team = GameServer()->m_pController->ClampTeam(Team); @@ -238,13 +249,17 @@ return; char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "'%s' joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + if(DoChatMsg) + { + str_format(aBuf, sizeof(aBuf), "'%s' joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team)); + GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + } KillCharacter(); m_Team = Team; m_LastActionTick = Server()->Tick(); + m_SpectatorID = SPEC_FREEVIEW; // we got to wait 0.5 secs before respawning m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2; str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team); diff -Nru teeworlds-0.6.1+dfsg/src/game/server/player.h teeworlds-0.6.2+dfsg/src/game/server/player.h --- teeworlds-0.6.1+dfsg/src/game/server/player.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/server/player.h 2013-05-01 11:47:39.000000000 +0000 @@ -20,7 +20,7 @@ void TryRespawn(); void Respawn(); - void SetTeam(int Team); + void SetTeam(int Team, bool DoChatMsg=true); int GetTeam() const { return m_Team; }; int GetCID() const { return m_ClientID; }; diff -Nru teeworlds-0.6.1+dfsg/src/game/variables.h teeworlds-0.6.2+dfsg/src/game/variables.h --- teeworlds-0.6.1+dfsg/src/game/variables.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/variables.h 2013-05-01 11:47:39.000000000 +0000 @@ -14,6 +14,7 @@ MACRO_CONFIG_INT(ClAutoswitchWeapons, cl_autoswitch_weapons, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Auto switch weapon on pickup") MACRO_CONFIG_INT(ClShowhud, cl_showhud, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ingame HUD") +MACRO_CONFIG_INT(ClShowChatFriends, cl_show_chat_friends, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show only chat messages from friends") MACRO_CONFIG_INT(ClShowfps, cl_showfps, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ingame FPS counter") MACRO_CONFIG_INT(ClAirjumpindicator, cl_airjumpindicator, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") @@ -41,7 +42,7 @@ MACRO_CONFIG_INT(PlayerColorFeet, player_color_feet, 65408, 0, 0xFFFFFF, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player feet color") MACRO_CONFIG_STR(PlayerSkin, player_skin, 24, "default", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player skin") -MACRO_CONFIG_INT(UiPage, ui_page, 5, 0, 10, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface page") +MACRO_CONFIG_INT(UiPage, ui_page, 6, 0, 10, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface page") MACRO_CONFIG_INT(UiToolboxPage, ui_toolbox_page, 0, 0, 2, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toolbox page") MACRO_CONFIG_STR(UiServerAddress, ui_server_address, 64, "localhost:8303", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface server address") MACRO_CONFIG_INT(UiScale, ui_scale, 100, 50, 150, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface scale") @@ -60,6 +61,7 @@ MACRO_CONFIG_INT(SvTeamdamage, sv_teamdamage, 0, 0, 1, CFGFLAG_SERVER, "Team damage") MACRO_CONFIG_STR(SvMaprotation, sv_maprotation, 768, "", CFGFLAG_SERVER, "Maps to rotate between") MACRO_CONFIG_INT(SvRoundsPerMap, sv_rounds_per_map, 1, 1, 100, CFGFLAG_SERVER, "Number of rounds on each map before rotating") +MACRO_CONFIG_INT(SvRoundSwap, sv_round_swap, 1, 0, 1, CFGFLAG_SERVER, "Swap teams between rounds") MACRO_CONFIG_INT(SvPowerups, sv_powerups, 1, 0, 1, CFGFLAG_SERVER, "Allow powerups like ninja") MACRO_CONFIG_INT(SvScorelimit, sv_scorelimit, 20, 0, 1000, CFGFLAG_SERVER, "Score limit (0 disables)") MACRO_CONFIG_INT(SvTimelimit, sv_timelimit, 0, 0, 1000, CFGFLAG_SERVER, "Time limit in minutes (0 disables)") diff -Nru teeworlds-0.6.1+dfsg/src/game/version.h teeworlds-0.6.2+dfsg/src/game/version.h --- teeworlds-0.6.1+dfsg/src/game/version.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/game/version.h 2013-05-01 11:47:39.000000000 +0000 @@ -3,6 +3,7 @@ #ifndef GAME_VERSION_H #define GAME_VERSION_H #include "generated/nethash.cpp" -#define GAME_VERSION "0.6.1" +#define GAME_VERSION "0.6.2" #define GAME_NETVERSION "0.6 " GAME_NETVERSION_HASH +static const char GAME_RELEASE_VERSION[8] = {'0', '.', '6', '.', '2', 0}; #endif diff -Nru teeworlds-0.6.1+dfsg/src/mastersrv/mastersrv.cpp teeworlds-0.6.2+dfsg/src/mastersrv/mastersrv.cpp --- teeworlds-0.6.1+dfsg/src/mastersrv/mastersrv.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/mastersrv/mastersrv.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -1,20 +1,24 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include -#include + +#include #include -#include #include +#include + +#include +#include +#include #include "mastersrv.h" + enum { MTU = 1400, MAX_SERVERS_PER_PACKET=75, MAX_PACKETS=16, MAX_SERVERS=MAX_SERVERS_PER_PACKET*MAX_PACKETS, - MAX_BANS=128, EXPIRE_TIME = 90 }; @@ -77,14 +81,7 @@ static CCountPacketData m_CountDataLegacy; -struct CBanEntry -{ - NETADDR m_Address; - int64 m_Expire; -}; - -static CBanEntry m_aBans[MAX_BANS]; -static int m_NumBans = 0; +CNetBan m_NetBan; static CNetClient m_NetChecker; // NAT/FW checker static CNetClient m_NetOp; // main @@ -217,9 +214,9 @@ } char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(pInfo, aAddrStr, sizeof(aAddrStr)); + net_addr_str(pInfo, aAddrStr, sizeof(aAddrStr), true); char aAltAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(pAlt, aAltAddrStr, sizeof(aAltAddrStr)); + net_addr_str(pAlt, aAltAddrStr, sizeof(aAltAddrStr), true); dbg_msg("mastersrv", "checking: %s (%s)", aAddrStr, aAltAddrStr); m_aCheckServers[m_NumCheckServers].m_Address = *pInfo; m_aCheckServers[m_NumCheckServers].m_AltAddress = *pAlt; @@ -237,7 +234,7 @@ if(net_addr_comp(&m_aServers[i].m_Address, pInfo) == 0) { char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(pInfo, aAddrStr, sizeof(aAddrStr)); + net_addr_str(pInfo, aAddrStr, sizeof(aAddrStr), true); dbg_msg("mastersrv", "updated: %s", aAddrStr); m_aServers[i].m_Expire = time_get()+time_freq()*EXPIRE_TIME; return; @@ -252,7 +249,7 @@ } char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(pInfo, aAddrStr, sizeof(aAddrStr)); + net_addr_str(pInfo, aAddrStr, sizeof(aAddrStr), true); dbg_msg("mastersrv", "added: %s", aAddrStr); m_aServers[m_NumServers].m_Address = *pInfo; m_aServers[m_NumServers].m_Expire = time_get()+time_freq()*EXPIRE_TIME; @@ -271,9 +268,9 @@ if(m_aCheckServers[i].m_TryCount == 10) { char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&m_aCheckServers[i].m_Address, aAddrStr, sizeof(aAddrStr)); + net_addr_str(&m_aCheckServers[i].m_Address, aAddrStr, sizeof(aAddrStr), true); char aAltAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&m_aCheckServers[i].m_AltAddress, aAltAddrStr, sizeof(aAltAddrStr)); + net_addr_str(&m_aCheckServers[i].m_AltAddress, aAltAddrStr, sizeof(aAltAddrStr), true); dbg_msg("mastersrv", "check failed: %s (%s)", aAddrStr, aAltAddrStr); // FAIL!! @@ -305,7 +302,7 @@ { // remove server char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&m_aServers[i].m_Address, aAddrStr, sizeof(aAddrStr)); + net_addr_str(&m_aServers[i].m_Address, aAddrStr, sizeof(aAddrStr), true); dbg_msg("mastersrv", "expired: %s", aAddrStr); m_aServers[i] = m_aServers[m_NumServers-1]; m_NumServers--; @@ -315,53 +312,9 @@ } } -bool CheckBan(NETADDR Addr) -{ - for(int i = 0; i < m_NumBans; i++) - { - if(net_addr_comp(&m_aBans[i].m_Address, &Addr) == 0) - { - return true; - } - } - Addr.port = 0; - for(int i = 0; i < m_NumBans; i++) - { - if(net_addr_comp(&m_aBans[i].m_Address, &Addr) == 0) - { - return true; - } - } - return false; -} - -void ConAddBan(IConsole::IResult *pResult, void *pUser) -{ - if(m_NumBans == MAX_BANS) - { - dbg_msg("mastersrv", "error: banlist is full"); - return; - } - - if(net_addr_from_str(&m_aBans[m_NumBans].m_Address, pResult->GetString(0)) != 0) - { - dbg_msg("mastersrv", "error: invalid address"); - return; - } - - if(CheckBan(m_aBans[m_NumBans].m_Address)) - { - dbg_msg("mastersrv", "duplicate ban: %s", pResult->GetString(0)); - return; - } - - dbg_msg("mastersrv", "ban added: %s", pResult->GetString(0)); - m_NumBans++; -} - void ReloadBans() { - m_NumBans = 0; + m_NetBan.UnbanAll(); m_pConsole->ExecuteFile("master.cfg"); } @@ -374,16 +327,44 @@ dbg_logger_stdout(); net_init(); - mem_zero(&BindAddr, sizeof(BindAddr)); - BindAddr.type = NETTYPE_ALL; - BindAddr.port = MASTERSERVER_PORT; + mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT)); + mem_copy(m_CountDataLegacy.m_Header, SERVERBROWSE_COUNT_LEGACY, sizeof(SERVERBROWSE_COUNT_LEGACY)); + + IKernel *pKernel = IKernel::Create(); + IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv); + IConfig *pConfig = CreateConfig(); + m_pConsole = CreateConsole(CFGFLAG_MASTER); + + bool RegisterFail = !pKernel->RegisterInterface(pStorage); + RegisterFail |= !pKernel->RegisterInterface(m_pConsole); + RegisterFail |= !pKernel->RegisterInterface(pConfig); + + if(RegisterFail) + return -1; + + pConfig->Init(); + m_NetBan.Init(m_pConsole, pStorage); + if(argc > 1) // ignore_convention + m_pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention + + if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0) + { + // got bindaddr + BindAddr.type = NETTYPE_ALL; + BindAddr.port = MASTERSERVER_PORT; + } + else + { + mem_zero(&BindAddr, sizeof(BindAddr)); + BindAddr.type = NETTYPE_ALL; + BindAddr.port = MASTERSERVER_PORT; + } if(!m_NetOp.Open(BindAddr, 0)) { dbg_msg("mastersrv", "couldn't start network (op)"); return -1; } - BindAddr.port = MASTERSERVER_PORT+1; if(!m_NetChecker.Open(BindAddr, 0)) { @@ -391,20 +372,8 @@ return -1; } - mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT)); - mem_copy(m_CountDataLegacy.m_Header, SERVERBROWSE_COUNT_LEGACY, sizeof(SERVERBROWSE_COUNT_LEGACY)); - - IKernel *pKernel = IKernel::Create(); - IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); - - m_pConsole = CreateConsole(CFGFLAG_MASTER); - m_pConsole->Register("ban", "s", CFGFLAG_MASTER, ConAddBan, 0, "Ban IP from mastersrv"); - - bool RegisterFail = !pKernel->RegisterInterface(pStorage); - RegisterFail |= !pKernel->RegisterInterface(m_pConsole); - - if(RegisterFail) - return -1; + // process pending commands + m_pConsole->StoreCommands(false); dbg_msg("mastersrv", "started"); @@ -418,7 +387,8 @@ while(m_NetOp.Recv(&Packet)) { // check if the server is banned - if(CheckBan(Packet.m_Address)) continue; + if(m_NetBan.IsBanned(&Packet.m_Address, 0, 0)) + continue; if(Packet.m_DataSize == sizeof(SERVERBROWSE_HEARTBEAT)+2 && mem_comp(Packet.m_pData, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT)) == 0) @@ -519,7 +489,8 @@ while(m_NetChecker.Recv(&Packet)) { // check if the server is banned - if(CheckBan(Packet.m_Address)) continue; + if(m_NetBan.IsBanned(&Packet.m_Address, 0, 0)) + continue; if(Packet.m_DataSize == sizeof(SERVERBROWSE_FWRESPONSE) && mem_comp(Packet.m_pData, SERVERBROWSE_FWRESPONSE, sizeof(SERVERBROWSE_FWRESPONSE)) == 0) diff -Nru teeworlds-0.6.1+dfsg/src/tools/crapnet.cpp teeworlds-0.6.2+dfsg/src/tools/crapnet.cpp --- teeworlds-0.6.1+dfsg/src/tools/crapnet.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/crapnet.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -129,7 +129,7 @@ if(m_ConfigLog) { char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&From, aAddrStr, sizeof(aAddrStr)); + net_addr_str(&From, aAddrStr, sizeof(aAddrStr), true); dbg_msg("crapnet", "<< %08d %s (%d)", p->m_ID, aAddrStr, p->m_DataSize); } } @@ -193,7 +193,7 @@ if(m_ConfigLog) { char aAddrStr[NETADDR_MAXSTRSIZE]; - net_addr_str(&p->m_SendTo, aAddrStr, sizeof(aAddrStr)); + net_addr_str(&p->m_SendTo, aAddrStr, sizeof(aAddrStr), true); dbg_msg("crapnet", ">> %08d %s (%d) %s", p->m_ID, aAddrStr, p->m_DataSize, aFlags); } diff -Nru teeworlds-0.6.1+dfsg/src/tools/dilate.cpp teeworlds-0.6.2+dfsg/src/tools/dilate.cpp --- teeworlds-0.6.1+dfsg/src/tools/dilate.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/dilate.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -96,7 +96,7 @@ dbg_msg("Usage", "%s FILE1 [ FILE2... ]", argv[0]); return -1; } - + for(int i = 1; i < argc; i++) DilateFile(argv[i]); return 0; diff -Nru teeworlds-0.6.1+dfsg/src/tools/fake_server.cpp teeworlds-0.6.2+dfsg/src/tools/fake_server.cpp --- teeworlds-0.6.1+dfsg/src/tools/fake_server.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/fake_server.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -113,7 +113,7 @@ int64 NextHeartBeat = 0; NETADDR BindAddr = {NETTYPE_IPV4, {0},0}; - if(!pNet->Open(BindAddr, 0, 0, 0)) + if(!pNet->Open(BindAddr, 0, 0, 0, 0)) return 0; while(1) diff -Nru teeworlds-0.6.1+dfsg/src/tools/map_resave.cpp teeworlds-0.6.2+dfsg/src/tools/map_resave.cpp --- teeworlds-0.6.1+dfsg/src/tools/map_resave.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/map_resave.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -6,7 +6,7 @@ int main(int argc, const char **argv) { - IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); + IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv); int Index, ID = 0, Type = 0, Size; void *pPtr; char aFileName[1024]; @@ -16,7 +16,7 @@ if(!pStorage || argc != 3) return -1; - str_format(aFileName, sizeof(aFileName), "maps/%s", argv[2]); + str_format(aFileName, sizeof(aFileName), "%s", argv[2]); if(!DataFile.Open(pStorage, argv[1], IStorage::TYPE_ALL)) return -1; diff -Nru teeworlds-0.6.1+dfsg/src/tools/map_version.cpp teeworlds-0.6.2+dfsg/src/tools/map_version.cpp --- teeworlds-0.6.1+dfsg/src/tools/map_version.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/map_version.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -44,7 +44,7 @@ int main(int argc, const char **argv) // ignore_convention { IKernel *pKernel = IKernel::Create(); - s_pStorage = CreateStorage("Teeworlds", argc, argv); + s_pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv); s_pEngineMap = CreateEngineMap(); bool RegisterFail = !pKernel->RegisterInterface(s_pStorage); diff -Nru teeworlds-0.6.1+dfsg/src/tools/tileset_borderadd.cpp teeworlds-0.6.2+dfsg/src/tools/tileset_borderadd.cpp --- teeworlds-0.6.1+dfsg/src/tools/tileset_borderadd.cpp 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/tileset_borderadd.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,86 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include +#include +#include + +typedef struct +{ + unsigned char r, g, b, a; +} CPixel; + +static void TilesetBorderadd(int w, int h, CPixel *pSrc, CPixel *pDest) +{ + int TileW = w/16; + int TileH = h/16; + + for(int tx = 0; tx < 16; tx++) + { + for(int ty = 0; ty < 16; ty++) + { + for(int x = 0; x < TileW + 4; x++) + { + for(int y = 0; y < TileH + 4; y++) + { + int SourceX = tx * TileW + clamp(x - 2, 0, TileW - 1); + int SourceY = ty * TileH + clamp(y - 2, 0, TileH - 1); + int DestX = tx * (TileW + 4) + x; + int DestY = ty * (TileH + 4) + y; + + int SourceI = SourceY * w + SourceX; + int DestI = DestY * (w + 16 * 4) + DestX; + + pDest[DestI] = pSrc[SourceI]; + + } + } + } + } +} + + +int FixFile(const char *pFileName) +{ + png_t Png; + CPixel *pBuffer[2] = {0,0}; + + png_init(0, 0); + png_open_file(&Png, pFileName); + + if(Png.color_type != PNG_TRUECOLOR_ALPHA) + { + dbg_msg("tileset_borderadd", "%s: not an RGBA image", pFileName); + return 1; + } + + int w = Png.width; + int h = Png.height; + + pBuffer[0] = (CPixel*)mem_alloc(w*h*sizeof(CPixel), 1); + pBuffer[1] = (CPixel*)mem_alloc((w+16*4)*(h+16*4)*sizeof(CPixel), 1); + png_get_data(&Png, (unsigned char *)pBuffer[0]); + png_close_file(&Png); + + TilesetBorderadd(w, h, pBuffer[0], pBuffer[1]); + + // save here + png_open_file_write(&Png, pFileName); + png_set_data(&Png, w + 16 * 4, h + 16 * 4, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)pBuffer[1]); + png_close_file(&Png); + + return 0; +} + +int main(int argc, const char **argv) +{ + dbg_logger_stdout(); + if(argc == 1) + { + dbg_msg("Usage", "%s FILE1 [ FILE2... ]", argv[0]); + return -1; + } + + for(int i = 1; i < argc; i++) + FixFile(argv[i]); + return 0; +} diff -Nru teeworlds-0.6.1+dfsg/src/tools/tileset_borderrem.cpp teeworlds-0.6.2+dfsg/src/tools/tileset_borderrem.cpp --- teeworlds-0.6.1+dfsg/src/tools/tileset_borderrem.cpp 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/tileset_borderrem.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,86 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include +#include +#include + +typedef struct +{ + unsigned char r, g, b, a; +} CPixel; + +static void TilesetBorderrem(int w, int h, CPixel *pSrc, CPixel *pDest) +{ + int TileW = w/16; + int TileH = h/16; + + for(int tx = 0; tx < 16; tx++) + { + for(int ty = 0; ty < 16; ty++) + { + for(int x = 0; x < TileW - 4; x++) + { + for(int y = 0; y < TileH - 4; y++) + { + int SourceX = tx * TileW + x + 2; + int SourceY = ty * TileH + y + 2; + int DestX = tx * (TileW - 4) + x; + int DestY = ty * (TileH - 4) + y; + + int SourceI = SourceY * w + SourceX; + int DestI = DestY * (w - 16 * 4) + DestX; + + pDest[DestI] = pSrc[SourceI]; + + } + } + } + } +} + + +int FixFile(const char *pFileName) +{ + png_t Png; + CPixel *pBuffer[2] = {0,0}; + + png_init(0, 0); + png_open_file(&Png, pFileName); + + if(Png.color_type != PNG_TRUECOLOR_ALPHA) + { + dbg_msg("tileset_borderrem", "%s: not an RGBA image", pFileName); + return 1; + } + + int w = Png.width; + int h = Png.height; + + pBuffer[0] = (CPixel*)mem_alloc(w*h*sizeof(CPixel), 1); + pBuffer[1] = (CPixel*)mem_alloc((w-16*4)*(h-16*4)*sizeof(CPixel), 1); + png_get_data(&Png, (unsigned char *)pBuffer[0]); + png_close_file(&Png); + + TilesetBorderrem(w, h, pBuffer[0], pBuffer[1]); + + // save here + png_open_file_write(&Png, pFileName); + png_set_data(&Png, w - 16 * 4, h - 16 * 4, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)pBuffer[1]); + png_close_file(&Png); + + return 0; +} + +int main(int argc, const char **argv) +{ + dbg_logger_stdout(); + if(argc == 1) + { + dbg_msg("Usage", "%s FILE1 [ FILE2... ]", argv[0]); + return -1; + } + + for(int i = 1; i < argc; i++) + FixFile(argv[i]); + return 0; +} diff -Nru teeworlds-0.6.1+dfsg/src/tools/tileset_borderset.cpp teeworlds-0.6.2+dfsg/src/tools/tileset_borderset.cpp --- teeworlds-0.6.1+dfsg/src/tools/tileset_borderset.cpp 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/tools/tileset_borderset.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,78 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include +#include +#include + +typedef struct +{ + unsigned char r, g, b, a; +} CPixel; + +static void TilesetBorderset(int w, int h, CPixel *pSrc, CPixel *pDest) +{ + int TileW = w/16; + int TileH = h/16; + + for(int tx = 0; tx < 16; tx++) + { + for(int ty = 0; ty < 16; ty++) + { + for(int x = 0; x < TileW; x++) + { + for(int y = 0; y < TileH; y++) + { + #define TILE_INDEX(tx_, ty_, x_, y_) (((ty_) * TileH + (y_)) * w + (tx_) * TileW + (x_)) + pDest[TILE_INDEX(tx, ty, x, y)] = pSrc[TILE_INDEX(tx, ty, clamp(x, 2, TileW - 3), clamp(y, 2, TileH - 3))]; + } + } + } + } +} + + +int FixFile(const char *pFileName) +{ + png_t Png; + CPixel *pBuffer[2] = {0,0}; + + png_init(0, 0); + png_open_file(&Png, pFileName); + + if(Png.color_type != PNG_TRUECOLOR_ALPHA) + { + dbg_msg("tileset_borderset", "%s: not an RGBA image", pFileName); + return 1; + } + + int w = Png.width; + int h = Png.height; + + pBuffer[0] = (CPixel*)mem_alloc(w*h*sizeof(CPixel), 1); + pBuffer[1] = (CPixel*)mem_alloc(w*h*sizeof(CPixel), 1); + png_get_data(&Png, (unsigned char *)pBuffer[0]); + png_close_file(&Png); + + TilesetBorderset(w, h, pBuffer[0], pBuffer[1]); + + // save here + png_open_file_write(&Png, pFileName); + png_set_data(&Png, w, h, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)pBuffer[1]); + png_close_file(&Png); + + return 0; +} + +int main(int argc, const char **argv) +{ + dbg_logger_stdout(); + if(argc == 1) + { + dbg_msg("Usage", "%s FILE1 [ FILE2... ]", argv[0]); + return -1; + } + + for(int i = 1; i < argc; i++) + FixFile(argv[i]); + return 0; +} diff -Nru teeworlds-0.6.1+dfsg/src/versionsrv/mapversions.h teeworlds-0.6.2+dfsg/src/versionsrv/mapversions.h --- teeworlds-0.6.1+dfsg/src/versionsrv/mapversions.h 1970-01-01 00:00:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/versionsrv/mapversions.h 2013-05-01 11:47:39.000000000 +0000 @@ -0,0 +1,22 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#ifndef VERSIONSRV_MAPVERSIONS_H +#define VERSIONSRV_MAPVERSIONS_H + +static CMapVersion s_aMapVersionList[] = { + {"ctf1", {0x06, 0xb5, 0xf1, 0x17}, {0x00, 0x00, 0x12, 0x38}}, + {"ctf2", {0x27, 0xbc, 0x5e, 0xac}, {0x00, 0x00, 0x64, 0x1a}}, + {"ctf3", {0xa3, 0x73, 0x9d, 0x41}, {0x00, 0x00, 0x17, 0x0f}}, + {"ctf4", {0xbe, 0x7c, 0x4d, 0xb9}, {0x00, 0x00, 0x2e, 0xfe}}, + {"ctf5", {0xd9, 0x21, 0x29, 0xa0}, {0x00, 0x00, 0x2f, 0x4c}}, + {"ctf6", {0x28, 0xc8, 0x43, 0x51}, {0x00, 0x00, 0x69, 0x2f}}, + {"ctf7", {0x1d, 0x35, 0x98, 0x72}, {0x00, 0x00, 0x15, 0x87}}, + {"dm1", {0xf2, 0x15, 0x9e, 0x6e}, {0x00, 0x00, 0x16, 0xad}}, + {"dm2", {0x71, 0x83, 0x98, 0x78}, {0x00, 0x00, 0x21, 0xdf}}, + {"dm6", {0x47, 0x4d, 0xa2, 0x35}, {0x00, 0x00, 0x1e, 0x95}}, + {"dm7", {0x42, 0x6d, 0xa1, 0x67}, {0x00, 0x00, 0x27, 0x2a}}, + {"dm8", {0x85, 0xf1, 0x1e, 0xd6}, {0x00, 0x00, 0x9e, 0xbd}}, + {"dm9", {0x42, 0xd4, 0x77, 0x7e}, {0x00, 0x00, 0x20, 0x11}}, +}; +static const int s_NumMapVersionItems = sizeof(s_aMapVersionList)/sizeof(CMapVersion); +#endif diff -Nru teeworlds-0.6.1+dfsg/src/versionsrv/versionsrv.cpp teeworlds-0.6.2+dfsg/src/versionsrv/versionsrv.cpp --- teeworlds-0.6.1+dfsg/src/versionsrv/versionsrv.cpp 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/versionsrv/versionsrv.cpp 2013-05-01 11:47:39.000000000 +0000 @@ -4,7 +4,10 @@ #include +#include + #include "versionsrv.h" +#include "mapversions.h" enum { MAX_MAPS_PER_PACKET=48, @@ -57,10 +60,10 @@ void SendVer(NETADDR *pAddr) { CNetChunk p; - unsigned char aData[sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)]; + unsigned char aData[sizeof(VERSIONSRV_VERSION) + sizeof(GAME_RELEASE_VERSION)]; mem_copy(aData, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)); - mem_copy(aData + sizeof(VERSIONSRV_VERSION), VERSION_DATA, sizeof(VERSION_DATA)); + mem_copy(aData + sizeof(VERSIONSRV_VERSION), GAME_RELEASE_VERSION, sizeof(GAME_RELEASE_VERSION)); p.m_ClientID = -1; p.m_Address = *pAddr; diff -Nru teeworlds-0.6.1+dfsg/src/versionsrv/versionsrv.h teeworlds-0.6.2+dfsg/src/versionsrv/versionsrv.h --- teeworlds-0.6.1+dfsg/src/versionsrv/versionsrv.h 2011-07-31 21:17:00.000000000 +0000 +++ teeworlds-0.6.2+dfsg/src/versionsrv/versionsrv.h 2013-05-01 11:47:39.000000000 +0000 @@ -11,25 +11,6 @@ unsigned char m_aSize[4]; }; -static CMapVersion s_aMapVersionList[] = { - {"ctf1", {0x06, 0xb5, 0xf1, 0x17}, {0x00, 0x00, 0x12, 0x38}}, - {"ctf2", {0x27, 0xbc, 0x5e, 0xac}, {0x00, 0x00, 0x64, 0x1a}}, - {"ctf3", {0xa3, 0x73, 0x9d, 0x41}, {0x00, 0x00, 0x17, 0x0f}}, - {"ctf4", {0xbe, 0x7c, 0x4d, 0xb9}, {0x00, 0x00, 0x2e, 0xfe}}, - {"ctf5", {0xd9, 0x21, 0x29, 0xa0}, {0x00, 0x00, 0x2f, 0x4c}}, - {"ctf6", {0x28, 0xc8, 0x43, 0x51}, {0x00, 0x00, 0x69, 0x2f}}, - {"ctf7", {0x1d, 0x35, 0x98, 0x72}, {0x00, 0x00, 0x15, 0x87}}, - {"dm1", {0xf2, 0x15, 0x9e, 0x6e}, {0x00, 0x00, 0x16, 0xad}}, - {"dm2", {0x71, 0x83, 0x98, 0x78}, {0x00, 0x00, 0x21, 0xdf}}, - {"dm6", {0x47, 0x4d, 0xa2, 0x35}, {0x00, 0x00, 0x1e, 0x95}}, - {"dm7", {0x42, 0x6d, 0xa1, 0x67}, {0x00, 0x00, 0x27, 0x2a}}, - {"dm8", {0x85, 0xf1, 0x1e, 0xd6}, {0x00, 0x00, 0x9e, 0xbd}}, - {"dm9", {0x42, 0xd4, 0x77, 0x7e}, {0x00, 0x00, 0x20, 0x11}}, -}; -static const int s_NumMapVersionItems = sizeof(s_aMapVersionList)/sizeof(CMapVersion); - -static const unsigned char VERSION_DATA[] = {0x00, 0, 6, 0}; - static const unsigned char VERSIONSRV_GETVERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 'g'}; static const unsigned char VERSIONSRV_VERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 's'};