2Moons codebase is over engineered and failing

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • 2Moons codebase is over engineered and failing

    I have a few suggestions that I think anyone taking on the legacy 2Moons code should give thought.The 2Moons code based is truly over engineered and it's causing failures to maintain that code base.

    1. Migrate out of Smarty and go pure PHP. Don't even bother making the mistake of upgrading to the latest version of Smarty. You will be wasting your time. Stick to version in the legacy code or better still bin Smarty altogether.

    2. Get out of Ajax. It just adds unnecessary complexity.

    3. Just migrate to PHP 8.x you achieve a faster core, smoother game play. Opt for PHP cache to be even faster.

    The 2Moons legacy codebase is dead. Frankly, it's been well and truly over engineered, creating unnecessary complexity, and making the code dead weight.

    Good luck.
  • Apologies. I didn't mean to sound negative. I'm trying to convey the message that you've got to take the legacy code, unravel the complexity which is causing multiple points of failures in code maintenance and rebuild using pure PHP 8.x. I would suggest to keep the current architecture. Go modular on the CSS, JS. If you really want to keep it simple, don't even bother with CSS just use Bootstrap5, Font awesome. That will even handle responsiveness. When using Smarty just hit delete. It will take ages to do but once done you are free to take the code forward any which way you like.
  • Hello everyone, many people here may not have the skills to undertake such an optimization project. Personally, I have a version currently under development, but as I said, it takes time and I'm quite busy in real life, so I'm not progressing as quickly as I'd like. In conclusion, I don't think what you're suggesting will be implemented here or shared.
    You can contact me by Discord : danter14
    Discord Galactic Conquest
    Video Youtube dev + tutorials

    Webside
  • flintnapa wrote:

    I have a few suggestions that I think anyone taking on the legacy 2Moons code should give thought.The 2Moons code based is truly over engineered and it's causing failures to maintain that code base.

    1. Migrate out of Smarty and go pure PHP. Don't even bother making the mistake of upgrading to the latest version of Smarty. You will be wasting your time. Stick to version in the legacy code or better still bin Smarty altogether.

    2. Get out of Ajax. It just adds unnecessary complexity.

    3. Just migrate to PHP 8.x you achieve a faster core, smoother game play. Opt for PHP cache to be even faster.

    The 2Moons legacy codebase is dead. Frankly, it's been well and truly over engineered, creating unnecessary complexity, and making the code dead weight.

    Good luck.

    1. I don't see any issue with current Smarty version under php 8.5, and the migration is quite easy. But maybe that's my biased opinion of who thinks a template engine (blade, smarty, whatever) is needed for entry level (likely most of the community here). But on one thing I agree, the current 2moons smarty version is with documented cve security vulnerabilities, stuck on php 7 or early 8 won't help either.

    2. problem isn't Ajax (I mean, async fetches are insanely better) but yes the js structure of 2moons. js has evolved, 2moons js hasn't, still heavily relies on DOM changes and niche js functions found on stack overflow like a browsergame from 2010

    3. true, at least php 8.4 - yeah many functions and vendors will broke, but that's the coin you have to pay for.
  • I would also say rewrite/refactor the whole fleet code. The legacy code breaks down with stuck fleet simply due to the complex way it's coded with a really unstable cron method. Scrap using fleet tokens. Modernise the fleet database. Essentially just delete the old fleet database and create it new. Then code it in PHP 8.x, js. You'll waste days trying to unravel stuck fleets and patching it up won't work. The short cut is to build it back up from scratch.
  • Ich bastle jetzt seit etwas länger als einem Jahr an 2Moons.

    Ich habe es fast fertig und stecke aktuell richtig viel Energie ins Design.

    Was bereits fertig ist und vollständig läuft:

    Ich habe PHP 8.0 auf PHP 8.3/8.4 umgestellt.

    Außerdem habe ich das komplette Template-System umgebaut – die aktuelle Version nutzt jetzt vollständig Twig.


    Sobald das Design abgeschlossen ist und alle Funktionen wirklich zuverlässig funktionieren, lade ich es hier hoch – mit der Absicht, dass 2Moons am Leben bleibt.

    Ich möchte dafür nichts haben. Ich möchte nur, dass ein Teil meiner Jugend bestehen bleibt.

    Ja, ich brauche länger als andere, weil ich im Umschreiben oder Schreiben von Code nicht perfekt bin.

    Es war wirklich eine Zerreißprobe.

    Wenn die Zeit gekommen ist, poste ich es hier und freue mich, wenn das die Community 2Moons weiter am Leben hält.

    Liebe Grüße

    I’ve been tinkering with 2Moons for a little over a year now.

    It’s almost finished, and I’m currently putting a lot of energy into the design.

    What’s already done and fully working:

    I upgraded PHP 8.0 to PHP 8.3/8.4.

    I also rebuilt the entire template system — the current version now uses Twig completely.


    Once the design is finished and all features are truly stable and working as intended, I’ll upload it here — with the goal of keeping 2Moons alive.

    I don’t want anything in return. I just want a piece of my youth to stay alive.

    Yes, it’s taking me longer than others, because I’m not perfect at rewriting or writing code.

    It’s been a real stress test.

    When the time is right, I’ll post it here, and I’ll be happy if the community helps keep 2Moons alive.

    Best regards
    SmartMoons – Community Beta
    Modernes 2Moons mit
    KI-Bots, PHP8.3 & 8.4, Twig
    UI/UX-Optik (clean + futuristisch)
    Jetzt testen & mithelfen
    Bitte
    /Bugs/Ideen per SupportTicket posten – ich bin dankbar für jeden Hinweis ❤️
  • Screenshot
    Images
    • Screenshot_20260206-143644~2.png

      214.38 kB, 1,344×2,183, viewed 93 times
    • Screenshot_20260206-143800~2.png

      250.23 kB, 1,344×2,468, viewed 106 times
    • Screenshot_20260206-143701~2.png

      214.34 kB, 1,344×2,520, viewed 104 times
    SmartMoons – Community Beta
    Modernes 2Moons mit
    KI-Bots, PHP8.3 & 8.4, Twig
    UI/UX-Optik (clean + futuristisch)
    Jetzt testen & mithelfen
    Bitte
    /Bugs/Ideen per SupportTicket posten – ich bin dankbar für jeden Hinweis ❤️
  • Big props to anyone even using 2moons anymore, there are other free versions are that are much better and alot more modern - theres even an ogame clone publicly available written in Laravel 12 - of course things take time to customize and develop but honestly if you cannot do it nowadays with ChatGPT/Claude then you will most likely never be able to do it.
  • What alternatives are there?
    What other games are available for OS?
    SmartMoons – Community Beta
    Modernes 2Moons mit
    KI-Bots, PHP8.3 & 8.4, Twig
    UI/UX-Optik (clean + futuristisch)
    Jetzt testen & mithelfen
    Bitte
    /Bugs/Ideen per SupportTicket posten – ich bin dankbar für jeden Hinweis ❤️
  • Game Designe, is 80% done!
    SmartMoons – Community Beta
    Modernes 2Moons mit
    KI-Bots, PHP8.3 & 8.4, Twig
    UI/UX-Optik (clean + futuristisch)
    Jetzt testen & mithelfen
    Bitte
    /Bugs/Ideen per SupportTicket posten – ich bin dankbar für jeden Hinweis ❤️
  • If I truly wanted to take this game further and make it open source for the benefit of the community, I would choose a C++ desktop architecture instead of a PHP/Web-based approach.

    In my opinion, building dedicated Client and Server applications and synchronizing them through a proper networking layer such as WinSock2 (or any modern cross-platform networking library like ASIO) provides far greater control, performance, and scalability than relying on JavaScript, Bootstrap, PHP, or other web technologies.

    With C++, you can design a real-time game loop that ticks and updates deterministically. You have full control over memory management, threading, and synchronization. Using tools like std::thread, std::mutex, std::lock_guard, std::unique_lock, and atomic operations, you can safely manage concurrency and prevent race conditions at the engine level — rather than depending on database-level locking like in MySQL.

    Unlike PHP’s request-response lifecycle, a C++ server runs persistently. This allows you to:
    • Maintain in-memory world state without constantly reading/writing to a database
    • Avoid heavy database contention and row-level locks
    • Eliminate many timing issues that cause lost resources, duplicated actions, or fleet inconsistencies
    • Implement fine-grained synchronization with RAII-based locking (e.g., std::lock_guard)
    You can also design scalable architectures such as:
    • Multi-threaded zone servers
    • Worker thread pools for combat simulations
    • Dedicated AI servers for bots
    • Event-driven networking using epoll / IOCP models
    From a performance standpoint, C++ gives you:
    • Deterministic execution
    • Lower latency
    • Zero garbage collection pauses
    • Direct memory control
    • Efficient use of STL containers for large-scale simulations
    For large battles or heavy simulation workloads, C++ can process calculations significantly faster than PHP, especially when using optimized data structures and cache-friendly designs.

    In short, instead of depending on stateless web requests and database synchronization, I would build a persistent C++ client-server architecture. This would allow the game to support thousands of concurrent players, handle complex simulations, and maintain consistency without suffering from performance bottlenecks or race conditions common in web-based systems.
  • flintnapa wrote:

    I would also say rewrite/refactor the whole fleet code. The legacy code breaks down with stuck fleet simply due to the complex way it's coded with a really unstable cron method. Scrap using fleet tokens. Modernise the fleet database. Essentially just delete the old fleet database and create it new. Then code it in PHP 8.x, js. You'll waste days trying to unravel stuck fleets and patching it up won't work. The short cut is to build it back up from scratch.
    do you have any error.log file which contains stuck fleets ? exceptionHandler inside general functions should be logging those. probably they throw expection before $fleet->setState(RETURNING) works. Maybe OPBE also causing some fleet to stuck by throwing exceptions ( negative ship number etc. ). Selecting user which is not existing anymore may also cause because $targetuser will return false.

    But in short, you should address error.log . Those could have been fixed if we had a nice log file which contains fleet stucking cases.
  • amamoslavida_ wrote:

    If I truly wanted to take this game further and make it open source for the benefit of the community, I would choose a C++ desktop architecture instead of a PHP/Web-based approach.

    In my opinion, building dedicated Client and Server applications and synchronizing them through a proper networking layer such as WinSock2 (or any modern cross-platform networking library like ASIO) provides far greater control, performance, and scalability than relying on JavaScript, Bootstrap, PHP, or other web technologies.

    With C++, you can design a real-time game loop that ticks and updates deterministically. You have full control over memory management, threading, and synchronization. Using tools like std::thread, std::mutex, std::lock_guard, std::unique_lock, and atomic operations, you can safely manage concurrency and prevent race conditions at the engine level — rather than depending on database-level locking like in MySQL.

    Unlike PHP’s request-response lifecycle, a C++ server runs persistently. This allows you to:
    • Maintain in-memory world state without constantly reading/writing to a database
    • Avoid heavy database contention and row-level locks
    • Eliminate many timing issues that cause lost resources, duplicated actions, or fleet inconsistencies
    • Implement fine-grained synchronization with RAII-based locking (e.g., std::lock_guard)
    You can also design scalable architectures such as:
    • Multi-threaded zone servers
    • Worker thread pools for combat simulations
    • Dedicated AI servers for bots
    • Event-driven networking using epoll / IOCP models
    From a performance standpoint, C++ gives you:
    • Deterministic execution
    • Lower latency
    • Zero garbage collection pauses
    • Direct memory control
    • Efficient use of STL containers for large-scale simulations
    For large battles or heavy simulation workloads, C++ can process calculations significantly faster than PHP, especially when using optimized data structures and cache-friendly designs.

    In short, instead of depending on stateless web requests and database synchronization, I would build a persistent C++ client-server architecture. This would allow the game to support thousands of concurrent players, handle complex simulations, and maintain consistency without suffering from performance bottlenecks or race conditions common in web-based systems.
    Zum Thema C++ vs. PHP/Web – technische Sicht & Projektziel

    Ich verstehe den Punkt komplett – rein aus Software-Architektur-Sicht wäre eine C++ Desktop-/Client-Server-Architektur natürlich die „Königsklasse“.

    Wenn ich das Projekt komplett neu entwickeln würde (Echtzeit-MMO, harte Performance-Anforderungen), dann wäre mein Ansatz:

    • []Dedizierter Client + dedizierter persistenter Server (kein klassisches Request-Response wie bei PHP) []Synchronisation über eine echte Networking-Schicht (z. B. WinSock2 oder moderne Cross-Platform-Libs wie ASIO)
    • Ein deterministischer Game-Loop (Ticks) statt stateless Web-Requests


    Warum das technisch stark ist:

    [list] []Persistenter Server-Prozess: World-State kann im RAM liegen, ohne ständig DB Read/Write. []Weniger DB-Contention: weniger Locks, weniger Row-Level-Konflikte als bei MySQL-heavy Designs. []Saubere Concurrency: Threading & Synchronisation im Engine-Layer statt „DB-Locking als Game-Mechanik“. []Determinismus & Performance: niedrige Latenz, keine GC-Pausen, direkter Memory- und Cache-Kontrollfluss. [/list]

    Beispiel: Was man damit elegant lösen kann

    [list] []In-memory World State (ohne ständige DB-Synchronisation) []Feingranulare Locks via RAII (z. B. std::lock_guard) []Worker-Pools für schwere Simulationen (Kampf/KB-Berechnung) []Zone-/Shard-Server, AI/Bot-Server, Event-driven IO (epoll / IOCP) [/list]

    ABER: Das verfehlt das Ziel von SmartMoons/2Moons Community Edition aus drei Gründen:

    1) Zugänglichkeit & Plattform
    2Moons ist ein Browsergame. Der Charme ist: einfach im Browser spielen – Smartphone, Tablet, Office-PC – ohne Installation.
    Ein C++ Desktop-Client würde diese Barrierefreiheit praktisch killen.

    2) Community-Faktor
    Die 2Moons-Community besteht überwiegend aus Leuten, die mit PHP, SQL, HTML groß geworden sind.
    Wenn ich jetzt einen komplexen C++ Stack mit Thread-Pooling, Mutex-Locking und eigener Engine veröffentliche, schließe ich 99% der Leute aus, für die ich das eigentlich mache.
    Dann könnte niemand mehr „mal eben“ ein Template bauen oder eine kleine Mod schreiben.

    3) Realismus / Zeit
    Ich bin ein Solo-Dev und mache das in meiner Freizeit, um ein Stück Jugend zu erhalten.
    Eine komplette Engine in C++ neu (Networking, Game-Loop, Simulation, Persistenz, Tools, UI) wäre ein Mehrjahresprojekt.
    Mein Ziel ist: die bestehende Basis so modernisieren, dass sie 2025/2026 sicher & stabil läuft:
    [list] []PHP 8.4 []Twig []sauberere Strukturen []modernes UI/UX [/list]

    Mein Ansatz ist Evolution statt Revolution.
    Ich will, dass 2Moons überlebt und nutzbar bleibt – und das geht am besten da, wo es hingehört: im Web.

    Trotzdem: Danke für den Input – technisch ist das natürlich die „Goldstandard“-Variante.
    Liebe Grüße


    On C++ vs. PHP/Web – architecture vs. project goals

    Thanks for the detailed technical feedback. From a pure software architecture perspective, you’re absolutely right: a persistent C++ client-server approach would be the “gold standard” in terms of performance and scalability.

    If I were building a real-time MMO from scratch, I would indeed go for:

    • []Dedicated client + dedicated persistent server (no PHP request-response lifecycle) []Proper networking layer (WinSock2 or modern cross-platform libs like ASIO)
    • Deterministic tick-based game loop instead of stateless web requests


    Why it’s strong technically:

    [list] []Persistent server process keeps world state in memory []Less database contention and fewer row-level locks []Concurrency handled on engine level (threads, mutexes, atomics) instead of DB locking []Deterministic execution, lower latency, no GC pauses, direct memory control [/list]

    However, that approach misses the goal of my “SmartMoons/2Moons Community Edition” project for three reasons:

    1) Accessibility & platform
    2Moons is a browser game. The charm is being able to play instantly on phone/tablet/PC without installing a client. A desktop C++ client would destroy that.

    2) The community
    Most of the 2Moons community consists of hobby devs/admins who grew up with PHP, SQL, and HTML. Publishing a complex C++ stack would alienate the vast majority of people I’m doing this for.

    3) Realism
    I’m a solo developer doing this in my spare time to preserve a piece of my youth. Rewriting an entire engine from scratch would take years. My goal is to modernize the existing base (PHP 8.4, Twig, cleaner structure) so it runs securely and stably in 2025/2026.

    My approach is evolution, not revolution.
    I want 2Moons to survive and remain usable — and that works best where it belongs: on the web.

    Nevertheless, thanks for the input — technically speaking, your suggestion is indeed the gold standard.
    Best regards
    SmartMoons – Community Beta
    Modernes 2Moons mit
    KI-Bots, PHP8.3 & 8.4, Twig
    UI/UX-Optik (clean + futuristisch)
    Jetzt testen & mithelfen
    Bitte
    /Bugs/Ideen per SupportTicket posten – ich bin dankbar für jeden Hinweis ❤️
  • Of course it takes way too long to fully rewrite this in c++, on the other hand the best approach would be to leave 2moons behind and rework an open source code such as github.com/lanedirt/ogamex, its written in Laravel 12, its modern but somewhat inefficiently coded on certain areas - though its a great source to start from since well... laravel 12 is actually modern while 2moons is nearly 20 years old - i do not see a reason to edit anything anymore on that old piece of code that was may be good in 2009-2016.
  • XenQen wrote:

    Of course it takes way too long to fully rewrite this in c++, on the other hand the best approach would be to leave 2moons behind and rework an open source code such as github.com/lanedirt/ogamex, its written in Laravel 12, its modern but somewhat inefficiently coded on certain areas - though its a great source to start from since well... laravel 12 is actually modern while 2moons is nearly 20 years old - i do not see a reason to edit anything anymore on that old piece of code that was may be good in 2009-2016.
    Great work indeed. people already contributing to that project and that is a good sign, as far as I see, many issues & PR s have been opened on git and that means someone working on it.

    However, I would not bother to deal with laravel ( if I am not interested in becoming web dev.), Sadly, same bugs which are independed of framework will stay (if not already fixed in that project).

    Besides of it, Having many alternatives is nice, beginners also need starting point and 2moons / steemnova is really simple for someone who don't have programming background. I know some people are hosting this to play with their friends or to write new modules.