game_machine 0.0.11 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +12 -1
- data/Gemfile.lock +32 -47
- data/Rakefile +0 -27
- data/bin/bundle_run.sh +1 -0
- data/bin/game_machine +29 -27
- data/config/cluster.conf +6 -5
- data/config/default.conf +164 -0
- data/config/game_machine.sql +33 -0
- data/config/game_messages.proto +87 -25
- data/config/gamecloud.conf +140 -0
- data/config/messages.proto +46 -53
- data/config/test.conf +149 -0
- data/game_machine.gemspec +10 -5
- data/games/boot.rb +3 -0
- data/games/example/data/game_data.yml +4 -4
- data/games/example/lib/aggressive_npc.rb +1 -1
- data/games/example/lib/game.rb +1 -2
- data/games/example/lib/player_register.rb +1 -1
- data/games/routes.rb +9 -0
- data/games/tutorial/boot.rb +12 -0
- data/games/tutorial/item_manager.rb +256 -0
- data/games/tutorial/object_store.rb +55 -0
- data/games/tutorial/seed.rb +52 -0
- data/games/tutorial/sql_store.rb +30 -0
- data/java/project/build.gradle +134 -0
- data/java/project/component.erb +719 -0
- data/java/{gradle.properties → project/gradle.properties} +1 -1
- data/java/project/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/{gradle → project/gradle}/wrapper/gradle-wrapper.properties +2 -2
- data/java/{gradlew → project/gradlew} +0 -0
- data/java/{gradlew.bat → project/gradlew.bat} +0 -0
- data/java/project/local_lib/AdminUi.jar +0 -0
- data/java/{local_lib/protostuff-compiler-1.0.7-jarjar.jar → project/local_lib/protostuff-compiler-1.0.8-jarjar.jar} +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-amd64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ia64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-pa-hpux-11.sl +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-aix-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-ppc64-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-s390x-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-sparc64-solaris.so +0 -0
- data/java/project/local_lib/sigar/libsigar-universal-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-universal64-macosx.dylib +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-5.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-freebsd-6.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-linux.so +0 -0
- data/java/project/local_lib/sigar/libsigar-x86-solaris.so +0 -0
- data/java/project/local_lib/sigar/sigar-amd64-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.dll +0 -0
- data/java/project/local_lib/sigar/sigar-x86-winnt.lib +0 -0
- data/java/project/model.erb +99 -0
- data/java/{settings.gradle → project/settings.gradle} +0 -0
- data/java/project/src/main/java/com/game_machine/authentication/DefaultAuthenticator.java +28 -0
- data/java/project/src/main/java/com/game_machine/authentication/PlayerAuthenticator.java +6 -0
- data/java/project/src/main/java/com/game_machine/authentication/PublicAuthenticator.java +20 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorFactory.java +0 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/ActorUtil.java +13 -0
- data/java/project/src/main/java/com/game_machine/core/AuthorizedPlayers.java +23 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageDecoder.java +36 -0
- data/java/project/src/main/java/com/game_machine/core/ClientMessageEncoder.java +19 -0
- data/java/project/src/main/java/com/game_machine/core/CloudClient.java +298 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/CommandProxy.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Commands.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/DatastoreCommands.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/DbConnectionPool.java +72 -0
- data/java/project/src/main/java/com/game_machine/core/DefaultMovementVerifier.java +56 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EntitySerializer.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/EntityTracking.java +119 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/EventStreamHandler.java +1 -1
- data/java/project/src/main/java/com/game_machine/core/GameActor.java +73 -0
- data/java/project/src/main/java/com/game_machine/core/GameMachineLoader.java +43 -0
- data/java/project/src/main/java/com/game_machine/core/GameMessageActor.java +44 -0
- data/java/project/src/main/java/com/game_machine/core/Grid.java +255 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/GridValue.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/Hashring.java +66 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/IActorFactory.java +0 -0
- data/java/project/src/main/java/com/game_machine/core/LocalLinkedBuffer.java +20 -0
- data/java/project/src/main/java/com/game_machine/core/MessageGateway.java +120 -0
- data/java/project/src/main/java/com/game_machine/core/MessagePersister.java +26 -0
- data/java/project/src/main/java/com/game_machine/core/MonoProxy.java +39 -0
- data/java/project/src/main/java/com/game_machine/core/MovementVerifier.java +7 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/NetMessage.java +10 -6
- data/java/project/src/main/java/com/game_machine/core/PersistentMessage.java +9 -0
- data/java/project/src/main/java/com/game_machine/core/PlayerCommands.java +31 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServer.java +100 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerHandler.java +54 -0
- data/java/project/src/main/java/com/game_machine/core/TcpServerInitializer.java +32 -0
- data/java/project/src/main/java/com/game_machine/core/UdpClient.java +86 -0
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServer.java +18 -27
- data/java/{src → project/src}/main/java/com/game_machine/core/UdpServerHandler.java +23 -26
- data/java/project/src/main/java/com/game_machine/core/Vector3.java +159 -0
- data/java/project/src/main/java/com/game_machine/orm/models/PlayerItem.java +118 -0
- data/java/project/src/main/java/com/game_machine/orm/models/TestObject.java +110 -0
- data/java/project/src/main/java/com/game_machine/tutorial/LootGenerator.java +26 -0
- data/java/{src → project/src}/main/resources/game_machine.java.stg +3 -1
- data/java/project/src/main/resources/logback.properties +13 -0
- data/java/project/src/main/resources/logback.xml +76 -0
- data/java/{src → project/src}/main/resources/protostuff.properties +0 -0
- data/java/src/main/java/game/MyGameActor.java +26 -0
- data/lib/game_machine.rb +17 -16
- data/lib/game_machine/actor.rb +1 -1
- data/lib/game_machine/actor/base.rb +8 -31
- data/lib/game_machine/actor/builder.rb +5 -6
- data/lib/game_machine/actor/game_actor.rb +55 -0
- data/lib/game_machine/actor/reloadable.rb +6 -1
- data/lib/game_machine/akka.rb +26 -32
- data/lib/game_machine/app_config.rb +39 -26
- data/lib/game_machine/application.rb +56 -62
- data/lib/game_machine/client_manager.rb +14 -8
- data/lib/game_machine/cloud_updater.rb +51 -0
- data/lib/game_machine/cluster_monitor.rb +3 -3
- data/lib/game_machine/commands.rb +1 -1
- data/lib/game_machine/commands/misc_commands.rb +4 -8
- data/lib/game_machine/commands/player_commands.rb +8 -0
- data/lib/game_machine/console.rb +1 -0
- data/lib/game_machine/console/build.rb +57 -24
- data/lib/game_machine/console/bundle.rb +95 -0
- data/lib/game_machine/console/deploy.rb +30 -0
- data/lib/game_machine/console/install.rb +70 -36
- data/lib/game_machine/console/server.rb +2 -69
- data/lib/game_machine/data_store.rb +111 -15
- data/lib/game_machine/data_stores/couchbase.rb +8 -3
- data/lib/game_machine/data_stores/gamecloud.rb +93 -0
- data/lib/game_machine/data_stores/jdbc.rb +98 -0
- data/lib/game_machine/default_handlers.rb +2 -0
- data/lib/game_machine/default_handlers/team_handler.rb +51 -0
- data/lib/game_machine/default_handlers/zone_manager.rb +30 -0
- data/lib/game_machine/endpoints.rb +0 -4
- data/lib/game_machine/endpoints/udp_incoming.rb +13 -5
- data/lib/game_machine/endpoints/udp_outgoing.rb +15 -9
- data/lib/game_machine/game_systems.rb +0 -2
- data/lib/game_machine/game_systems/agents/controller.rb +2 -2
- data/lib/game_machine/game_systems/entity_tracking.rb +0 -3
- data/lib/game_machine/game_systems/region_manager.rb +3 -2
- data/lib/game_machine/game_systems/region_service.rb +2 -2
- data/lib/game_machine/game_systems/remote_echo.rb +10 -0
- data/lib/game_machine/game_systems/team_manager.rb +2 -11
- data/lib/game_machine/grid.rb +5 -18
- data/lib/game_machine/handlers/authentication.rb +1 -9
- data/lib/game_machine/handlers/game.rb +27 -2
- data/lib/game_machine/handlers/player_authentication.rb +87 -0
- data/lib/game_machine/handlers/request.rb +9 -11
- data/lib/game_machine/hocon_config.rb +81 -0
- data/lib/game_machine/java_lib.rb +14 -1
- data/lib/game_machine/logger.rb +10 -23
- data/lib/game_machine/models.rb +1 -0
- data/lib/game_machine/mono_server.rb +6 -1
- data/lib/game_machine/object_db.rb +12 -6
- data/lib/game_machine/protobuf.rb +1 -1
- data/lib/game_machine/protobuf/game_messages.rb +13 -3
- data/lib/game_machine/protobuf/generate.rb +107 -5
- data/lib/game_machine/restart_watcher.rb +1 -1
- data/lib/game_machine/routes.rb +23 -0
- data/lib/game_machine/scheduler.rb +1 -1
- data/lib/game_machine/securerandom.rb +2 -0
- data/lib/game_machine/system_stats.rb +28 -7
- data/lib/game_machine/version.rb +1 -1
- data/lib/game_machine/wavefront_ext.rb +47 -0
- data/lib/game_machine/write_behind_cache.rb +24 -9
- data/mono/server/Makefile +1 -1
- data/mono/server/Newtonsoft.Json.dll +0 -0
- data/mono/server/build.bat +1 -1
- data/mono/server/callable.cs +9 -0
- data/mono/server/echo.cs +17 -0
- data/mono/server/message_router.cs +16 -23
- data/mono/server/messages.cs +1792 -417
- data/mono/server/protobuf-net.dll +0 -0
- data/mono/server/server.cs +120 -0
- data/mono/server/server.exe +0 -0
- data/pathfinding/astar.cpp +149 -0
- data/pathfinding/build.sh +6 -0
- data/pathfinding/build.txt +16 -0
- data/pathfinding/crowd.cpp +194 -0
- data/pathfinding/include/astar.h +49 -0
- data/pathfinding/include/common.h +5 -0
- data/pathfinding/include/crowd.h +43 -0
- data/pathfinding/include/micropather.h +511 -0
- data/pathfinding/include/navmesh.h +114 -0
- data/pathfinding/include/pathfinder.h +24 -0
- data/pathfinding/main.cpp +108 -17
- data/pathfinding/micropather.cpp +1062 -0
- data/pathfinding/navmesh.cpp +408 -0
- data/pathfinding/overrides/DetourCrowd.cpp +1446 -0
- data/pathfinding/overrides/DetourNavMeshQuery.cpp +3551 -0
- data/pathfinding/overrides/DetourNavMeshQuery.h +538 -0
- data/pathfinding/pathfinder.cpp +117 -0
- data/pathfinding/{bin → premake}/premake4 +0 -0
- data/pathfinding/premake/premake4.exe +0 -0
- data/pathfinding/premake4.lua +12 -3
- data/spec/actor/actor_spec.rb +0 -7
- data/spec/client_manager_spec.rb +1 -1
- data/spec/couchproxy_spec.rb +38 -0
- data/spec/entity_persistence_spec.rb +129 -0
- data/spec/game_systems/team_manager_spec.rb +2 -2
- data/spec/hashring_spec.rb +17 -39
- data/spec/java_grid_spec.rb +0 -2
- data/spec/misc_spec.rb +111 -0
- data/spec/mono_spec.rb +50 -3
- data/spec/reliable_message_spec.rb +38 -0
- data/spec/spec_helper.rb +4 -4
- data/spec/spec_helper_minimal.rb +10 -0
- data/web/app.rb +108 -86
- data/web/config/trinidad.yml +1 -0
- data/web/views/add_player.erb +25 -0
- data/web/views/index.erb +0 -0
- data/web/views/layout.erb +48 -0
- data/web/views/login.erb +25 -0
- data/web/views/players.erb +24 -0
- metadata +209 -94
- data/config/config.example.yml +0 -100
- data/config/regions.example.yml +0 -9
- data/games/example/lib/authentication_handler.rb +0 -69
- data/games/models.rb +0 -3
- data/games/models/clan_member.rb +0 -8
- data/games/models/clan_profile.rb +0 -9
- data/games/models/player.rb +0 -7
- data/games/plugins.rb +0 -1
- data/games/plugins/team_handler.rb +0 -49
- data/games/preload.rb +0 -13
- data/java/.gitignore +0 -1
- data/java/build.gradle +0 -95
- data/java/component.erb +0 -396
- data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +0 -25
- data/java/src/main/java/com/game_machine/core/Grid.java +0 -195
- data/java/src/main/resources/logback.xml +0 -14
- data/java/src/main/resources/logging.properties +0 -3
- data/lib/game_machine/actor/mono_actor.rb +0 -89
- data/lib/game_machine/auth_handlers/base.rb +0 -21
- data/lib/game_machine/auth_handlers/public.rb +0 -34
- data/lib/game_machine/endpoints/mono_gateway.rb +0 -87
- data/lib/game_machine/endpoints/tcp.rb +0 -51
- data/lib/game_machine/endpoints/tcp_handler.rb +0 -75
- data/lib/game_machine/endpoints/udp.rb +0 -88
- data/lib/game_machine/game_loader.rb +0 -46
- data/lib/game_machine/game_systems/region_settings.rb +0 -13
- data/lib/game_machine/hashring.rb +0 -48
- data/lib/game_machine/settings.rb +0 -11
- data/mono/server/actor.cs +0 -37
- data/mono/server/iactor.cs +0 -11
- data/mono/server/message_util.cs +0 -29
- data/mono/server/proxy_client.cs +0 -73
- data/mono/server/proxy_server.cs +0 -30
- data/mono/server/test_actor.cs +0 -33
- data/pathfinding/include/pathfind.h +0 -167
- data/pathfinding/pathfind.cpp +0 -174
- data/pathfinding/pathfinder.cs +0 -66
- data/script/server.sh +0 -109
- data/script/watch.sh +0 -11
- data/spec/commands/navigation_commands_spec.rb +0 -51
- data/spec/game_systems/entity_tracking_spec.rb +0 -64
- data/spec/navigation/detour_navmesh_spec.rb +0 -34
- data/spec/navigation/detour_path_spec.rb +0 -25
- data/spec/udp_server_spec.rb +0 -10
- data/web/controllers/auth_controller.rb +0 -19
- data/web/controllers/base_controller.rb +0 -16
- data/web/controllers/index_controller.rb +0 -7
- data/web/controllers/log_controller.rb +0 -47
- data/web/controllers/messages_controller.rb +0 -59
- data/web/controllers/player_register_controller.rb +0 -15
- data/web/views/game_messages.haml +0 -45
- data/web/views/index.haml +0 -6
- data/web/views/layout.haml +0 -41
- data/web/views/logs.haml +0 -32
- data/web/views/player_register.haml +0 -22
- data/web/views/player_registered.haml +0 -2
- data/web/views/register_layout.haml +0 -22
- data/web/views/restart.haml +0 -35
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
#Thu Aug 21 21:28:37 PDT 2014
|
|
2
2
|
distributionBase=GRADLE_USER_HOME
|
|
3
3
|
distributionPath=wrapper/dists
|
|
4
4
|
zipStoreBase=GRADLE_USER_HOME
|
|
5
5
|
zipStorePath=wrapper/dists
|
|
6
|
-
distributionUrl=
|
|
6
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip
|
|
File without changes
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
package com.game_machine.orm.models;
|
|
2
|
+
|
|
3
|
+
import org.javalite.activejdbc.DB;
|
|
4
|
+
import org.javalite.activejdbc.Model;
|
|
5
|
+
import org.javalite.activejdbc.annotations.IdName;
|
|
6
|
+
|
|
7
|
+
import com.game_machine.core.DbConnectionPool;
|
|
8
|
+
import com.zaxxer.hikari.HikariDataSource;
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
Postgresql
|
|
12
|
+
|
|
13
|
+
Database/user creation
|
|
14
|
+
CREATE ROLE gamemachine WITH ENCRYPTED PASSWORD 'gamemachine' LOGIN CREATEDB CREATEROLE;
|
|
15
|
+
CREATE DATABASE gamemachine WITH OWNER=gamemachine ENCODING='UTF8';
|
|
16
|
+
|
|
17
|
+
Table
|
|
18
|
+
CREATE TABLE <%= klass.underscore.pluralize %> (
|
|
19
|
+
id bigserial NOT NULL,
|
|
20
|
+
<% message.getFields.each do |field| %>
|
|
21
|
+
<%= sql_field(klass,field,'postgres') %>
|
|
22
|
+
<% end %>
|
|
23
|
+
|
|
24
|
+
<% message_fields.each do |message_field| %>
|
|
25
|
+
<% klass_message = messages_index[message_field] %>
|
|
26
|
+
<% klass_message.getFields.each do |field| %>
|
|
27
|
+
<%= sql_field(message_field,field,'postgres',true) %>
|
|
28
|
+
<% end %>
|
|
29
|
+
<% end %>
|
|
30
|
+
|
|
31
|
+
player_id character varying(128) NOT NULL,
|
|
32
|
+
CONSTRAINT <%=klass.underscore%>_pkey PRIMARY KEY (id),
|
|
33
|
+
CONSTRAINT <%=klass.underscore%>_id_player_id_idx UNIQUE (<%=klass.underscore%>_id,player_id)
|
|
34
|
+
);
|
|
35
|
+
alter table <%= klass.underscore.pluralize %> owner to gamemachine;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Mysql
|
|
39
|
+
|
|
40
|
+
Database/user creation
|
|
41
|
+
CREATE DATABASE IF NOT EXISTS gamemachine CHARACTER SET utf8 COLLATE utf8_general_ci;
|
|
42
|
+
GRANT ALL PRIVILEGES ON gamemachine.* TO 'gamemachine'@'%' IDENTIFIED BY 'gamemachine' WITH GRANT OPTION;
|
|
43
|
+
FLUSH PRIVILEGES;
|
|
44
|
+
|
|
45
|
+
Table
|
|
46
|
+
CREATE TABLE `<%= klass.underscore.pluralize %>` (
|
|
47
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
48
|
+
<% message.getFields.each do |field| %>
|
|
49
|
+
<%= sql_field(klass,field,'mysql') %>
|
|
50
|
+
<% end %>
|
|
51
|
+
|
|
52
|
+
<% message_fields.each do |message_field| %>
|
|
53
|
+
<% klass_message = messages_index[message_field] %>
|
|
54
|
+
<% klass_message.getFields.each do |field| %>
|
|
55
|
+
<%= sql_field(message_field,field,'mysql',true) %>
|
|
56
|
+
<% end %>
|
|
57
|
+
<% end %>
|
|
58
|
+
|
|
59
|
+
`player_id` varchar(128) NOT NULL,
|
|
60
|
+
PRIMARY KEY(`id`),
|
|
61
|
+
UNIQUE KEY `<%=klass.underscore%>_id_player_id_idx` (`<%=klass.underscore%>_id`,`player_id`)
|
|
62
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
public class <%= klass %> extends Model {
|
|
66
|
+
|
|
67
|
+
public static void openTransaction() {
|
|
68
|
+
open();
|
|
69
|
+
DB db = new DB("default");
|
|
70
|
+
db.openTransaction();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public static void commitTransaction() {
|
|
74
|
+
DB db = new DB("default");
|
|
75
|
+
db.commitTransaction();
|
|
76
|
+
close();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static void rollbackTransaction() {
|
|
80
|
+
DB db = new DB("default");
|
|
81
|
+
db.rollbackTransaction();
|
|
82
|
+
close();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public static void close() {
|
|
86
|
+
DB db = new DB("default");
|
|
87
|
+
if(db.hasConnection()) {
|
|
88
|
+
db.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public static void open() {
|
|
93
|
+
DB db = new DB("default");
|
|
94
|
+
if(!db.hasConnection()) {
|
|
95
|
+
HikariDataSource ds = DbConnectionPool.getInstance().getDataSource("game_machine_orm");
|
|
96
|
+
db.open(ds);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.game_machine.authentication;
|
|
2
|
+
|
|
3
|
+
import org.mindrot.jbcrypt.BCrypt;
|
|
4
|
+
|
|
5
|
+
import GameMachine.Messages.Player;
|
|
6
|
+
|
|
7
|
+
public class DefaultAuthenticator implements PlayerAuthenticator {
|
|
8
|
+
|
|
9
|
+
private static String scope = "players";
|
|
10
|
+
public Player player;
|
|
11
|
+
|
|
12
|
+
public DefaultAuthenticator(Player player) {
|
|
13
|
+
this.player = player;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public void setPassword(String password) {
|
|
17
|
+
player.setPasswordHash(BCrypt.hashpw(password, BCrypt.gensalt()));
|
|
18
|
+
player.storeSet(scope);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public boolean authenticate(String password) {
|
|
22
|
+
if (player.hasPasswordHash()) {
|
|
23
|
+
return BCrypt.checkpw(password, player.getPasswordHash());
|
|
24
|
+
} else {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.game_machine.authentication;
|
|
2
|
+
|
|
3
|
+
import GameMachine.Messages.Player;
|
|
4
|
+
|
|
5
|
+
public class PublicAuthenticator implements PlayerAuthenticator {
|
|
6
|
+
|
|
7
|
+
public PublicAuthenticator(Player player) {
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@Override
|
|
12
|
+
public void setPassword(String password) {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
public boolean authenticate(String password) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
File without changes
|
|
@@ -2,17 +2,30 @@ package com.game_machine.core;
|
|
|
2
2
|
|
|
3
3
|
import akka.actor.ActorSelection;
|
|
4
4
|
import akka.actor.ActorSystem;
|
|
5
|
+
import akka.actor.Address;
|
|
6
|
+
import akka.cluster.Cluster;
|
|
5
7
|
|
|
6
8
|
import com.typesafe.config.Config;
|
|
7
9
|
import com.typesafe.config.ConfigFactory;
|
|
8
10
|
|
|
9
11
|
public class ActorUtil {
|
|
10
12
|
|
|
13
|
+
public static void joinCluster(String protocol, String name, String host, int port) {
|
|
14
|
+
ActorSystem system = GameMachineLoader.getActorSystem();
|
|
15
|
+
Address address = new Address(protocol,name,host,port);
|
|
16
|
+
Cluster.get(system).join(address);
|
|
17
|
+
}
|
|
11
18
|
|
|
12
19
|
public static ActorSelection getSelectionByClass(Class<?> klass) {
|
|
13
20
|
return GameMachineLoader.getActorSystem().actorSelection("/user/"+ klass.getSimpleName());
|
|
14
21
|
}
|
|
15
22
|
|
|
23
|
+
public static ActorSelection findDistributed(String name, String id) {
|
|
24
|
+
String server = Hashring.getHashring("servers").nodeFor(id);
|
|
25
|
+
String actorName = Hashring.getHashring(name).nodeFor(id);
|
|
26
|
+
return GameMachineLoader.getActorSystem().actorSelection(server+"/user/"+ actorName);
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
public static ActorSelection getSelectionByName(String name) {
|
|
17
30
|
return GameMachineLoader.getActorSystem().actorSelection("/user/"+ name);
|
|
18
31
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.game_machine.core;
|
|
2
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
3
|
+
|
|
4
|
+
public class AuthorizedPlayers {
|
|
5
|
+
public ConcurrentHashMap<String, Boolean> authorized = new ConcurrentHashMap<String, Boolean>();
|
|
6
|
+
|
|
7
|
+
public void setAuthorized(String playerId) {
|
|
8
|
+
authorized.put(playerId, true);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public void remove(String playerId) {
|
|
12
|
+
authorized.remove(playerId);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public Boolean isAuthorized(String playerId) {
|
|
16
|
+
if (authorized.containsKey(playerId)) {
|
|
17
|
+
return true;
|
|
18
|
+
} else {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.game_machine.core;
|
|
2
|
+
|
|
3
|
+
import io.netty.buffer.ByteBuf;
|
|
4
|
+
import io.netty.channel.ChannelHandler.Sharable;
|
|
5
|
+
import io.netty.channel.ChannelHandlerContext;
|
|
6
|
+
import io.netty.handler.codec.MessageToMessageDecoder;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
import GameMachine.Messages.ClientMessage;
|
|
11
|
+
|
|
12
|
+
import com.dyuproject.protostuff.ProtobufIOUtil;
|
|
13
|
+
import com.dyuproject.protostuff.runtime.RuntimeSchema;
|
|
14
|
+
|
|
15
|
+
@Sharable
|
|
16
|
+
public class ClientMessageDecoder extends MessageToMessageDecoder<ByteBuf> {
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
|
|
20
|
+
final byte[] array;
|
|
21
|
+
final int offset;
|
|
22
|
+
final int length = msg.readableBytes();
|
|
23
|
+
if (msg.hasArray()) {
|
|
24
|
+
array = msg.array();
|
|
25
|
+
offset = msg.arrayOffset() + msg.readerIndex();
|
|
26
|
+
} else {
|
|
27
|
+
array = new byte[length];
|
|
28
|
+
msg.getBytes(msg.readerIndex(), array, 0, length);
|
|
29
|
+
offset = 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ClientMessage message = new ClientMessage();
|
|
33
|
+
ProtobufIOUtil.mergeFrom(array, offset, length, message, RuntimeSchema.getSchema(ClientMessage.class));
|
|
34
|
+
out.add(message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.game_machine.core;
|
|
2
|
+
|
|
3
|
+
import static io.netty.buffer.Unpooled.wrappedBuffer;
|
|
4
|
+
import io.netty.channel.ChannelHandlerContext;
|
|
5
|
+
import io.netty.handler.codec.MessageToMessageEncoder;
|
|
6
|
+
|
|
7
|
+
import java.util.List;
|
|
8
|
+
|
|
9
|
+
import GameMachine.Messages.ClientMessage;
|
|
10
|
+
|
|
11
|
+
public class ClientMessageEncoder extends MessageToMessageEncoder<ClientMessage> {
|
|
12
|
+
@Override
|
|
13
|
+
protected void encode(ChannelHandlerContext ctx, ClientMessage msg, List<Object> out) throws Exception {
|
|
14
|
+
if (msg instanceof ClientMessage) {
|
|
15
|
+
out.add(wrappedBuffer(msg.toPrefixedByteArray()));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
package com.game_machine.core;
|
|
2
|
+
|
|
3
|
+
import java.io.IOException;
|
|
4
|
+
import java.io.UnsupportedEncodingException;
|
|
5
|
+
import java.net.URLEncoder;
|
|
6
|
+
import java.nio.charset.Charset;
|
|
7
|
+
import java.security.MessageDigest;
|
|
8
|
+
import java.security.NoSuchAlgorithmException;
|
|
9
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
10
|
+
|
|
11
|
+
import org.apache.http.HttpEntity;
|
|
12
|
+
import org.apache.http.HttpResponse;
|
|
13
|
+
import org.apache.http.client.ClientProtocolException;
|
|
14
|
+
import org.apache.http.client.ResponseHandler;
|
|
15
|
+
import org.apache.http.client.methods.HttpDelete;
|
|
16
|
+
import org.apache.http.client.methods.HttpGet;
|
|
17
|
+
import org.apache.http.client.methods.HttpPost;
|
|
18
|
+
import org.apache.http.client.methods.HttpPut;
|
|
19
|
+
import org.apache.http.entity.ByteArrayEntity;
|
|
20
|
+
import org.apache.http.entity.ContentType;
|
|
21
|
+
import org.apache.http.entity.StringEntity;
|
|
22
|
+
import org.apache.http.impl.client.CloseableHttpClient;
|
|
23
|
+
import org.apache.http.impl.client.HttpClients;
|
|
24
|
+
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
25
|
+
import org.apache.http.util.EntityUtils;
|
|
26
|
+
import org.slf4j.Logger;
|
|
27
|
+
import org.slf4j.LoggerFactory;
|
|
28
|
+
|
|
29
|
+
import GameMachine.Messages.NodeStatus;
|
|
30
|
+
|
|
31
|
+
public class CloudClient {
|
|
32
|
+
|
|
33
|
+
public ConcurrentHashMap<String, CloseableHttpClient> clients = new ConcurrentHashMap<String, CloseableHttpClient>();
|
|
34
|
+
private PoolingHttpClientConnectionManager cm;
|
|
35
|
+
private String gamecloudApiKey;
|
|
36
|
+
private String gamecloudUser;
|
|
37
|
+
private String host;
|
|
38
|
+
private static final Logger logger = LoggerFactory.getLogger(CloudClient.class);
|
|
39
|
+
|
|
40
|
+
public class CloudResponse {
|
|
41
|
+
public int status;
|
|
42
|
+
public byte[] byteBody;
|
|
43
|
+
public String stringBody;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private CloudClient() {
|
|
47
|
+
// Some freaking moron at apache.org decided it was a good idea to ignore log level and force WIRE
|
|
48
|
+
// level whenever Hyperic sigar is detected.
|
|
49
|
+
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
|
|
50
|
+
|
|
51
|
+
cm = new PoolingHttpClientConnectionManager();
|
|
52
|
+
cm.setMaxTotal(10);
|
|
53
|
+
// Increase default max connection per route to 20
|
|
54
|
+
cm.setDefaultMaxPerRoute(10);
|
|
55
|
+
// Increase max connections for localhost:80 to 50
|
|
56
|
+
// HttpHost localhost = new HttpHost("locahost", 80);
|
|
57
|
+
// cm.setMaxPerRoute(new HttpRoute(localhost), 50);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private static class LazyHolder {
|
|
61
|
+
private static final CloudClient INSTANCE = new CloudClient();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static CloudClient getInstance() {
|
|
65
|
+
return LazyHolder.INSTANCE;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sets the credentials for the gamecloud that are used in all requests
|
|
70
|
+
*
|
|
71
|
+
* @param host
|
|
72
|
+
* @param username
|
|
73
|
+
* @param apiKey
|
|
74
|
+
*/
|
|
75
|
+
public void setCredentials(String host, String username, String apiKey) {
|
|
76
|
+
gamecloudApiKey = apiKey;
|
|
77
|
+
gamecloudUser = username;
|
|
78
|
+
this.host = host;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Performs a left anchored fuzzy search by id
|
|
83
|
+
*
|
|
84
|
+
* @param query
|
|
85
|
+
* @param limit
|
|
86
|
+
* @param format
|
|
87
|
+
* @return
|
|
88
|
+
* @throws ClientProtocolException
|
|
89
|
+
* @throws IOException
|
|
90
|
+
*/
|
|
91
|
+
public CloudResponse query(String query, int limit, String format) throws ClientProtocolException, IOException {
|
|
92
|
+
String url = "http://" + host + "/api/db-query/" + gamecloudUser + "/" + encodeURIComponent(query) + "/" + limit + "/" + format;
|
|
93
|
+
String token = hash256(gamecloudUser + query + gamecloudApiKey);
|
|
94
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
95
|
+
HttpGet request = new HttpGet(url);
|
|
96
|
+
request.setHeader("X-Auth", token);
|
|
97
|
+
return httpClient.execute(request, new ByteArrayResponseHandler());
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Performs mass delete based on a left anchored fuzzy search by id
|
|
102
|
+
*
|
|
103
|
+
* @param query
|
|
104
|
+
* @return
|
|
105
|
+
* @throws ClientProtocolException
|
|
106
|
+
* @throws IOException
|
|
107
|
+
*/
|
|
108
|
+
public CloudResponse deleteMatching(String query) throws ClientProtocolException, IOException {
|
|
109
|
+
String url = "http://" + host + "/api/db-delete-matching/" + gamecloudUser + "/" + encodeURIComponent(query);
|
|
110
|
+
String token = hash256(gamecloudUser + query + gamecloudApiKey);
|
|
111
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
112
|
+
HttpDelete request = new HttpDelete(url);
|
|
113
|
+
request.setHeader("X-Auth", token);
|
|
114
|
+
return httpClient.execute(request, new StringResponseHandler());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* @param nodeStatus
|
|
120
|
+
* @return
|
|
121
|
+
* @throws ClientProtocolException
|
|
122
|
+
* @throws IOException
|
|
123
|
+
*/
|
|
124
|
+
public CloudResponse updateNodeStatus(NodeStatus nodeStatus) throws ClientProtocolException, IOException {
|
|
125
|
+
String url = "http://" + host + "/api/update_node_status";
|
|
126
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
127
|
+
HttpPost request = new HttpPost(url);
|
|
128
|
+
ByteArrayEntity input = new ByteArrayEntity(nodeStatus.toByteArray(), ContentType.APPLICATION_OCTET_STREAM);
|
|
129
|
+
request.setEntity(input);
|
|
130
|
+
return httpClient.execute(request, new StringResponseHandler());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* @param id
|
|
136
|
+
* @param bytes
|
|
137
|
+
* @return
|
|
138
|
+
* @throws ClientProtocolException
|
|
139
|
+
* @throws IOException
|
|
140
|
+
*/
|
|
141
|
+
public CloudResponse putBytes(String id, byte[] bytes) throws ClientProtocolException, IOException {
|
|
142
|
+
String url = urlFrom(id, "bytes");
|
|
143
|
+
String token = hash256(gamecloudUser + id + gamecloudApiKey);
|
|
144
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
145
|
+
HttpPut request = new HttpPut(url);
|
|
146
|
+
ByteArrayEntity input = new ByteArrayEntity(bytes, ContentType.APPLICATION_OCTET_STREAM);
|
|
147
|
+
request.setEntity(input);
|
|
148
|
+
request.setHeader("X-Auth", token);
|
|
149
|
+
return httpClient.execute(request, new StringResponseHandler());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
*
|
|
154
|
+
* @param id
|
|
155
|
+
* @param value
|
|
156
|
+
* @return
|
|
157
|
+
* @throws ClientProtocolException
|
|
158
|
+
* @throws IOException
|
|
159
|
+
*/
|
|
160
|
+
public CloudResponse putString(String id, String value) throws ClientProtocolException, IOException {
|
|
161
|
+
String url = urlFrom(id, "json");
|
|
162
|
+
String token = hash256(gamecloudUser + id + gamecloudApiKey);
|
|
163
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
164
|
+
HttpPut request = new HttpPut(url);
|
|
165
|
+
StringEntity input = new StringEntity(value, ContentType.TEXT_PLAIN);
|
|
166
|
+
request.setEntity(input);
|
|
167
|
+
request.setHeader("X-Auth", token);
|
|
168
|
+
return httpClient.execute(request, new StringResponseHandler());
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @param id
|
|
174
|
+
* @return
|
|
175
|
+
* @throws ClientProtocolException
|
|
176
|
+
* @throws IOException
|
|
177
|
+
*/
|
|
178
|
+
public CloudResponse delete(String id) throws ClientProtocolException, IOException {
|
|
179
|
+
String url = urlFrom(id, null);
|
|
180
|
+
String token = hash256(gamecloudUser + id + gamecloudApiKey);
|
|
181
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
182
|
+
HttpDelete request = new HttpDelete(url);
|
|
183
|
+
request.setHeader("X-Auth", token);
|
|
184
|
+
return httpClient.execute(request, new StringResponseHandler());
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
*
|
|
189
|
+
* @param id
|
|
190
|
+
* @return
|
|
191
|
+
* @throws ClientProtocolException
|
|
192
|
+
* @throws IOException
|
|
193
|
+
*/
|
|
194
|
+
public CloudResponse getBytes(String id) throws ClientProtocolException, IOException {
|
|
195
|
+
String url = urlFrom(id, "bytes");
|
|
196
|
+
String token = hash256(gamecloudUser + id + gamecloudApiKey);
|
|
197
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
198
|
+
HttpGet request = new HttpGet(url);
|
|
199
|
+
request.setHeader("X-Auth", token);
|
|
200
|
+
return httpClient.execute(request, new ByteArrayResponseHandler());
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
*
|
|
205
|
+
* @param id
|
|
206
|
+
* @return
|
|
207
|
+
* @throws ClientProtocolException
|
|
208
|
+
* @throws IOException
|
|
209
|
+
*/
|
|
210
|
+
public CloudResponse getString(String id) throws ClientProtocolException, IOException {
|
|
211
|
+
String url = urlFrom(id, "json");
|
|
212
|
+
String token = hash256(gamecloudUser + id + gamecloudApiKey);
|
|
213
|
+
CloseableHttpClient httpClient = getClient("gamemachine");
|
|
214
|
+
HttpGet request = new HttpGet(url);
|
|
215
|
+
request.setHeader("X-Auth", token);
|
|
216
|
+
return httpClient.execute(request, new StringResponseHandler());
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private CloseableHttpClient getClient(String id) {
|
|
220
|
+
CloseableHttpClient httpClient;
|
|
221
|
+
if (clients.containsKey(id)) {
|
|
222
|
+
httpClient = clients.get(id);
|
|
223
|
+
} else {
|
|
224
|
+
httpClient = HttpClients.custom().setConnectionManager(cm).build();
|
|
225
|
+
clients.put(id, httpClient);
|
|
226
|
+
}
|
|
227
|
+
return httpClient;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private String hash256(String data) {
|
|
231
|
+
try {
|
|
232
|
+
MessageDigest md;
|
|
233
|
+
md = MessageDigest.getInstance("SHA-256");
|
|
234
|
+
md.update(data.getBytes());
|
|
235
|
+
return bytesToHex(md.digest());
|
|
236
|
+
} catch (NoSuchAlgorithmException e) {
|
|
237
|
+
e.printStackTrace();
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private String bytesToHex(byte[] bytes) {
|
|
243
|
+
StringBuffer result = new StringBuffer();
|
|
244
|
+
for (byte byt : bytes)
|
|
245
|
+
result.append(Integer.toString((byt & 0xff) + 0x100, 16).substring(1));
|
|
246
|
+
return result.toString();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private String encodeURIComponent(String s) {
|
|
250
|
+
String result;
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
result = URLEncoder.encode(s, "UTF-8").replaceAll("\\+", "%20").replaceAll("\\%21", "!")
|
|
254
|
+
.replaceAll("\\%27", "'").replaceAll("\\%28", "(").replaceAll("\\%29", ")")
|
|
255
|
+
.replaceAll("\\%7E", "~");
|
|
256
|
+
} catch (UnsupportedEncodingException e) {
|
|
257
|
+
result = s;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private String urlFrom(String id, String format) throws UnsupportedEncodingException {
|
|
264
|
+
if (format == null) {
|
|
265
|
+
return "http://" + host + "/api/db/" + gamecloudUser + "/" + encodeURIComponent(id);
|
|
266
|
+
} else {
|
|
267
|
+
return "http://" + host + "/api/db/" + gamecloudUser + "/" + encodeURIComponent(id) + "/" + format;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private class StringResponseHandler implements ResponseHandler<CloudResponse> {
|
|
273
|
+
public CloudResponse handleResponse(final HttpResponse response) throws IOException {
|
|
274
|
+
CloudResponse couchResponse = new CloudResponse();
|
|
275
|
+
int status = response.getStatusLine().getStatusCode();
|
|
276
|
+
couchResponse.status = status;
|
|
277
|
+
HttpEntity entity = response.getEntity();
|
|
278
|
+
if (entity != null) {
|
|
279
|
+
couchResponse.stringBody = EntityUtils.toString(entity);
|
|
280
|
+
}
|
|
281
|
+
return couchResponse;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private class ByteArrayResponseHandler implements ResponseHandler<CloudResponse> {
|
|
286
|
+
public CloudResponse handleResponse(final HttpResponse response) throws IOException {
|
|
287
|
+
int status = response.getStatusLine().getStatusCode();
|
|
288
|
+
CloudResponse couchResponse = new CloudResponse();
|
|
289
|
+
couchResponse.status = status;
|
|
290
|
+
HttpEntity entity = response.getEntity();
|
|
291
|
+
if (entity != null) {
|
|
292
|
+
couchResponse.byteBody = EntityUtils.toByteArray(entity);
|
|
293
|
+
}
|
|
294
|
+
return couchResponse;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
}
|