2026-10-17Translated from the Japanese original

[AI Mahjong Dojo] Play with friends just by sending an invitation URL! Implementation guide for the online multiplayer feature

Have you ever thought, "I want my friends to be able to easily play the AI tool I created"? In this post, we will take a deep dive into the technology and the specific points of focus behind the online multiplayer feature of "AI Mahjong Dojo," which was developed by the operator utilizing AI (Claude).

Key points
  • Instant online play possible without account registration or port forwarding thanks to Cloudflare's tunnel technology.
  • The design strictly ensures "no cheating" by centralizing match processing on the host's PC to prevent others from seeing your hand.
  • Implemented defense measures against trolls, such as connection limits, message count restrictions, and automatic disconnection for repeated failed entry attempts.
  • Verified not only fully automated match progression and reconnection behavior but also that "the CPU's judgment does not change even if hidden tiles are manipulated."
[AI Mahjong Dojo] Play with friends just by sending an invitation URL! Implementation guide for the online multiplayer feature

Introduction: Pursuing "Ease of Use" without account registration

When conducting matches over the internet, the biggest hurdle is "environment setup." Normally, to expose your own PC as a server, it often requires complex port forwarding (changing router settings) or user account registration. However, for this online multiplayer feature, we adopted Cloudflare's (a cloud-based infrastructure service) temporary tunnel technology. This allows the opponent to join the match without any special settings whatsoever, simply by having the host send an invitation URL. This design, which prioritizes "ease of use," is a major point of this update.

  • Easily create rooms with a 4-character room code
  • CPUs automatically fill empty seats, so you can play without worrying about the number of players
  • Achieved a stress-free experience where the game automatically plays when time runs out and allows you to return to the same seat even if the connection is lost

Technical Points: Ensuring Information Privacy and Fairness

The most important thing in online multiplayer is "fairness." If all calculations are performed on each player's terminal, it becomes possible to "cheat" by eavesdropping on communications or rewriting programs to peek at other players' hands. To solve this problem, we introduced a mechanism where all match processing is completed solely on the host's PC (the match server). Each player's browser is designed to receive only their own hand and information that is publicly disclosed by the rules. This creates a structure where information cannot be stolen from the outside.

  • Centralized match processing: Everything is processed on the host's PC
  • Information restriction: Only own hand and public information are sent to each player
  • Verified: Confirmed that the CPU's judgment does not change even if the order of hidden tiles is manipulated

"Troll Countermeasures" for Safety

In online multiplayer where an unspecified number of people might access the system, measures against "trolling" by malicious users are essential. This implementation incorporates the following three defense measures. First, setting a limit on the number of simultaneous connections. Next, limiting the number of messages sent and received. And finally, a mechanism that automatically disconnects the connection when it detects behavior such as repeatedly failing to enter a room. By taking these measures, we have prepared an environment where users can safely enjoy matches within the community.

  • Connection limit settings
  • Message count limits
  • Disconnection function for consecutive entry failures

Test Results and Future Outlook

Prior to release, we conducted operation tests under various conditions. We thoroughly verified fully automated match progression, reconnection during communication loss, behavior when time runs out, and ensuring that hand data does not leak. Please note that this online multiplayer feature is currently implemented as a feature of the "PC version." It is not available on the Web version published on the blog at this time. In the next installment (Part 6), we will explain the clever tricks for the "What to discard" problem, where beginners often get stuck, and mechanisms to improve more smoothly.

  • Verified fully automated match, reconnection, and time-out behaviors
  • Verified that no hand data leakage occurs
  • Next theme: The "What to discard" problem and tricks to help beginners avoid getting stuck

Summary

By utilizing AI, it is possible to efficiently build complex online multiplayer systems. By understanding the technical background, you might see hints on how to master AI as a "tool." When sharing a tool you've created with friends, what is the one thing you want to prioritize most? Please let us know in the comments.

Useful for
  • People who want to actually develop and operate AI tools
  • People interested in network technology or security
  • People who want to actually experience AI Mahjong Dojo
Glossary
Port forwarding
The operation of changing the settings of network equipment such as routers to allow communication from the outside to reach a specific program (such as a server).
Cloudflare Tunnel
Technology that safely establishes a communication path to a specific server or PC without going through complex network settings.

FAQ

Can I play online on the Web version too?

According to official information, the online multiplayer feature is for the PC version and is not available on the Web version playable on the blog.

Summary

Implementation guide for online multiplayer: Technology balancing safety and ease of use

This article was translated from Japanese by AI; numbers and model names were automatically checked against the original. The original was written with AI from the sources cited there.