Git Product home page Git Product logo

congcoi123 / tenio Goto Github PK

View Code? Open in Web Editor NEW
111.0 7.0 13.0 33.16 MB

TenIO is an open-source project for making online games that includes a java NIO (Non-blocking I/O) based server specifically designed for multiplayer games and simple existing game clients for rapid development: Libgdx (Java), Cocos2d-x (C++), Unity (C#), Phaserjs (Javascript).

Home Page: https://congcoi123.dev

License: MIT License

Java 100.00%
netty multiplayer cocos2d-x libgdx unity phaserjs gameserver architecture mmo mmorpg

tenio's Introduction

TenIO Tweet

TenIO is an open-source project to create multiplayer online games that includes a java NIO (Non-blocking I/O) based server specifically designed for multiplayer games, which supports UDP, TCP, Websocket, HTTP transports, and available simple client projects for quick development.

Features

  • Scalable, distributed design
  • Easy-to-use, OOP design
  • Based on standard Java development, ensuring cross-platform support
  • Simple event handlers implementation
  • Simple physic simulator and debugger
  • Have simple existing game clients for rapid development

Showcases


Game Box Online


Gold Miner Online


Brick Game Online

First Glimpse

Simple Movement Simulation
Simple Movement Simulation

Simple Implementation

  • Establishes a simple server with only a single Java class
/**
 * This class shows how a simple server handle messages that came from a client.
 */
@Bootstrap
public final class TestSimpleServer {

  public static void main(String[] params) {
    ApplicationLauncher.run(TestSimpleServer.class, params);
  }

  /**
   * Create your own configurations.
   */
  @Setting
  public static class TestConfiguration extends CoreConfiguration implements Configuration {

    @Override
    protected void extend(Map<String, String> extProperties) {
      for (Map.Entry<String, String> entry : extProperties.entrySet()) {
        var paramName = entry.getKey();
        push(ExampleConfigurationType.getByValue(paramName), String.valueOf(entry.getValue()));
      }
    }
  }

  /**
   * Define your handlers.
   */

  @EventHandler
  public static class ConnectionEstablishedHandler extends AbstractHandler
      implements EventConnectionEstablishedResult {

    @Override
    public void handle(Session session, DataCollection message,
                       ConnectionEstablishedResult result) {
      if (result == ConnectionEstablishedResult.SUCCESS) {
        var request = (ZeroMap) message;

        api().login(request.getString(SharedEventKey.KEY_PLAYER_LOGIN), session);
      }
    }
  }

  @EventHandler
  public static class PlayerLoggedInHandler extends AbstractHandler
      implements EventPlayerLoggedinResult<Player> {

    @Override
    public void handle(Player player, PlayerLoggedInResult result) {
      if (result == PlayerLoggedInResult.SUCCESS) {
        var parcel = map().putString(SharedEventKey.KEY_PLAYER_LOGIN,
            String.format("Welcome to server: %s", player.getName()));

        response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
      }
    }
  }

  @EventHandler
  public static class ReceivedMessageFromPlayerHandler extends AbstractHandler
      implements EventReceivedMessageFromPlayer<Player> {

    @Override
    public void handle(Player player, DataCollection message) {
      var parcel =
          map().putString(SharedEventKey.KEY_CLIENT_SERVER_ECHO, String.format("Echo(%s): %s",
              player.getName(),
              ((ZeroMap) message).getString(SharedEventKey.KEY_CLIENT_SERVER_ECHO)));

      response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
    }
  }
}
  • Supports self-defined commands to interact with the server conveniently
  1. Usage
2022-11-20 05:20:38,256 [main] INFO  com.tenio.core.server.ServerImpl - [SERVER][Example] Started
$ help
help - Shows all supporting commands
  [<command>,<command>,<command>]
info - Provides brief information about players and rooms on the server
  player
  room
player - Logout the first player from the server
  logout first
server - Allows stopping or restarting the server
  stop
  restart
unban - Allows removing banned Ip addresses from the ban list
  [<address>,<command>,<command>]
$ info player
> There are 1 players > The first 10 entities > [Player{name='IkjvI', properties={}, session=Session{id=0, name='IkjvI', transportType=TCP, createdTime=1668918078524, lastReadTime=1668918078524, lastWriteTime=1668918078524, lastActivityTime=1668918078524, readBytes=75, writtenBytes=120, droppedPackets=0, inactivatedTime=0, datagramRemoteSocketAddress=null, clientAddress='127.0.0.1', clientPort=60659, serverPort=8032, serverAddress='127.0.0.1', maxIdleTimeInSecond=0, activated=true, connected=true, hasUdp=false, enabledKcp=false, hasKcp=false}, currentRoom=null, state=null, roleInRoom=SPECTATOR, lastLoginTime=1668918078589, lastJoinedRoomTime=1668918078588, playerSlotInCurrentRoom=-1, loggedIn=true, activated=true, hasSession=true}]
$ 
  1. Make sure to set the command usage flag in setting.json file to be enabled
{
  "command": {
    "enabled": true
  },
  "plugin": {
    "enabled": false,
    "path": "/plugin"
  }
}
  1. Simple implementation
@Command(label = "player", usage = {
    "logout first"
}, description = "Logout the first player from the server")
public class PlayerCommand extends AbstractCommandHandler {

  @Override
  public void execute(List<String> args) {
    var action = args.get(0);
    var param = args.get(1);

    if (action.equals("logout") && param.equals("first")) {
      var players = api().getReadonlyPlayersList();
      if (players.isEmpty()) {
        CommandUtility.INSTANCE.showConsoleMessage("Empty list of players.");
        return;
      }
      var firstPlayer = players.get(0);
      CommandUtility.INSTANCE.showConsoleMessage("Player {" + firstPlayer.getName() + "} is " +
          "going to logout.");
      api().logout(firstPlayer);
    } else {
      CommandUtility.INSTANCE.showConsoleMessage("Invalid action.");
    }
  }
}

Wiki

The wiki provides implementation level details and answers to general questions that a developer starting to use TenIO might have about it.

Clients


TenIO Cocos2dx


TenIO Libgdx


TenIO Unity


TenIO Phaserjs

Framework

The project is strongly based on the same name framework as you can be referenced by the following repositories.

Requirements

- Java 17

License

The TenIO project is currently available under the MIT License.

Contributing

Please check out the contributing guideline for more details.

Documentations

Please check out the documentations directory for more details.

Installation

$ git clone https://github.com/congcoi123/tenio.git

Examples

Collection

Please check out this repository for references.

Wanna try Kotlin?

Then you should check out this showcase for more details.

Happy coding !

tenio's People

Contributors

congcoi123 avatar dependabot[bot] avatar loclv avatar tengamesinc avatar wasabmyan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tenio's Issues

[TEN-132] Server Clusters

At the first design, a single game server works standalone. However, it could be better if it can work together with another game server as a cluster.
The details of design and implementation need to be concerned thoroughly.

[feature] allow define multiple connection type

  • Allow define multiple connection types in the configuration file
  • Handle message communication based on the type of connection
	<Network>
		<Sockets>
                         <Socket> <!-- The first element is always treated the main connection -->
                                 <Id>main</Id>
                                 <Port>8032</Port>
                                 <Type>TCP</Type>
                         </Socket>
                         <Socket>
                                 <Id>action</Id>
                                 <Port>8033</Port>
                                 <Type>UDP</Type>
                         </Socket>
                         <Socket>
                                 <Id>chat</Id>
                                 <Port>8034</Port>
                                 <Type>TCP</Type>
                         </Socket>
		</Sockets>
		<WebSockets>
                         <WebSocket> <!-- The first element is always treated the main connection -->
                                 <Id>main</Id>
                                 <Port>8035</Port>
                         </WebSocket>
                         <WebSocket>
                                 <Id>chat</Id>
                                 <Port>8036</Port>
                         </WebSocket>
                         <WebSocket>
                                 <Id>action</Id>
                                 <Port>8037</Port>
                         </WebSocket>
                 </WebSockets>
	</Network>

[hotfix] Circle Dependencies

  • Instance initialization problems: A -> B -> C
    -> So it needs to create C first and B and lastly A

  • Circle Dependencies: A -> B -> C -> A
    -> Needs for detecting this circle and report it to the user

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.