Skip to content

Commit be11a28

Browse files
authored
Merge pull request #7 from Techbot/drupal_user_create
Automatically create and authenticate Drupal users from Discord users
2 parents d5785a8 + 19bcf75 commit be11a28

File tree

629 files changed

+19254
-579
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

629 files changed

+19254
-579
lines changed

Diff for: .gitignore

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.vscode
2+
.DS_Store
3+
.env*
24

3-
/config/
45
/vendor/
56

67
# Assets and user uploads
@@ -11,6 +12,7 @@
1112

1213
# mine
1314
tiled
15+
server/.env*
1416
server/lib
1517
server/reports
1618
server/arena.config.ts
@@ -25,7 +27,6 @@ client/.parcel-cache
2527
client/src/game/backend.ts
2628
client/src/assets/fonts/*
2729

28-
node_modules
2930
LICENSE.md
3031

3132
config_init
@@ -36,6 +37,3 @@ _phaser_server
3637
_phaser_client
3738

3839
public/
39-
40-
server/.env*
41-

Diff for: README.md

+66-16
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,98 @@
2323
* [The Eclectic Meme Conspiracy Online - Game Scripts](https://docs.google.com/document/d/1rdpK02PXfvUjwQLJgLXHzOeSbtBHymMo8Wq35UMY42s/)
2424
* [The Eclectic Meme Conspiracy - Game Information](https://docs.google.com/spreadsheets/d/18frZlc8CwXpQ6V0slhlR1qcUyX5OijrPhJUCGY2S6hw/edit#gid=1469334051)
2525

26-
### Steps to build a world from the engine.
26+
## Installation
2727

2828
#### Drupal Setup
2929
* Install Drupal (Minimal Install)
30-
* Download required modules (Paragraphs, Flag, Profile, Registration Role)
30+
* Download required modules (Paragraphs, Flag, Profile, Registration Role, Rest API Auth)
3131

32-
`composer require 'drupal/profile:^1.10' 'drupal/paragraphs:^1.17' 'drupal/flag:^4.0@beta' 'drupal/registration_role:^2.0'`
32+
`composer require 'drupal/profile:^1.10' 'drupal/paragraphs:^1.17' 'drupal/flag:^4.0@beta' 'drupal/registration_role:^2.0' 'drupal/rest_api_authentication:^2.0' 'drupal/file_field_replace:^3.0'`
3333

3434
* Helpful Drupal configurations:
3535
* Administration =>Appearance => Claro => Install and set as default
3636
* Administration => Extend => Toolbar
3737

38-
* Clone Jigs into modules/custom/jigs or
39-
* Install Drupal/Jigs
38+
* Clone Jigs4Discord into modules/custom/jigs
39+
* Enable the required modules before installing the JiGS module (saves execution time)
40+
* The JiGS Dependencies module is included for convenience.
41+
* Install the JiGS module
4042
* Install the default content - https://github.com/Techbot/JiGS-demo-content
4143
* If you followed these instructions, all you need to do is turn on the module.
4244
* Clone assets into /web/assets/ - https://github.com/Techbot/JiGS-demo-assets
45+
* Go to Configuration => JSON:API and accept all operations
46+
* Go to Configuration => API Authentication Configuration
47+
* Enable Authentication
48+
* Choose API Key Authentication
49+
* Generate New API Key
50+
* You will need to assign the Administrator role to the user you want to use for API access
51+
* For some hosting scenarios, you may need to configure your CORS settings on both Drupal main and the /assets folder.
52+
* Configure /sites/default/default.services.yml
53+
* Add an .htaccess to /assets
54+
4355

4456
#### Colyseus Setup
4557
* cd into modules/custom/jigs/server
4658
* `npm install`
4759
* copy src/services/db_SETUP.ts into src/services/db.ts and configure
4860
* Copy example.env to .env and configure
49-
* npm run start
61+
* Add your administrator username and the API key from the previous section
5062

5163
#### Phaser Setup
5264
* cd into modules/custom/jigs/client
53-
* Copy example.env to .env and configure
65+
* Copy example.env.* to .env.* and configure
5466
* `npm install`
55-
* `npm run build`
56-
* Copy the css & js paths into modules/custom/jigs/jigs.libraries.yml and increment the version number
57-
* Run `npm run start`
58-
* In a new tab, run `npm tunnel`
59-
* Put the cloudflared URL into your Discord app's OAuth and URL Mappings
60-
* Test your new Discord app!
6167

62-
#### Testing Drupal Setup
68+
## Testing
69+
Steps to do rapid development and testing without the need to build the client and bundle into Drupal for every code change.
70+
71+
### Local Development
72+
* Add a fake discord_id to your user account in Drupal (i.e. 12345)
73+
* Set your client's .env.development Drupal URLs to /drupal
74+
* In server run `npm run start`
75+
* In client run `npm run start`
76+
* In your browser, open http://localhost:5173/?discord_id=12345
77+
* You should see the game running and the HUD populated with your user information
78+
* Click in and you should be able to run around on the map!
79+
80+
### Discord Testing
81+
* In client run `npm run tunnel`
82+
* In your Discord configuration:
83+
* URL Mappings: / = tunnel URL
84+
* OAuth2: Redirects = tunnel URL
85+
* Run your Discord activity and you should be able to run around on the map!
86+
87+
## Production
88+
Steps to bundle the client into Drupal and deploy the servers to a cloud provider.
89+
90+
### Local Setup
91+
* Set your client's .env.production Drupal URLs to blank
92+
* Optionally point assets URL at a CDN server
93+
* In client run `NODE_ENV=production && npm run build`
94+
* Copy the css & js paths into modules/custom/jigs/jigs.libraries.yml and increment the version number
95+
* In server run `npm run start`
6396
* In Drupal, go to Administration => Configuration => Development => Performance and clear all caches
6497
* Go to the home page and verify that the game is running
65-
* Note: You might need to configure your webserver to route wildcard hostnames through to your Drupal folder!
6698

67-
#### World Setup
99+
### Tunnel
100+
* If you have necessary ports open (80,2567), you can just run:
101+
* `cloudflared tunnel --url http://localhost`
102+
* Server URL will be tunnel:2567
103+
* Drupal URL will be tunnel (or tunnel:8080 or however you have Apache configured)
104+
* If you need to tunnel to servers individually you can run:
105+
* In server run `npm run tunnel`
106+
* For Drupal run `cloudflared tunnel --url http://localhost`
107+
* Note: You might need to configure your webserver to route wildcard hostnames through to your Drupal folder!
108+
109+
### Discord
110+
* In your Discord configuration:
111+
* OAuth2: Redirects = Server URL
112+
* URL Mappings:
113+
* / = Drupal URL
114+
* /api = Server URL
115+
* OAuth2: Redirects = Server URL
116+
117+
## World Setup
68118
* Design the content (Drupal) see https://www.emc23.com/jigs-drupal-and-content-modelling
69119
* Design relationships between the above content data and the players (mysql queries dropped into a folder triggered by the heartbeats- aka Agenda.js)
70120

Diff for: client/example.env

-2
This file was deleted.

Diff for: client/example.env.development

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Rename this from example.env to .env
2+
VITE_DISCORD_CLIENT_ID=PASTE_OAUTH2_CLIENT_ID_HERE
3+
4+
# Change to /drupal if you want to use vite server config
5+
# Change to blank when you're ready to bundle directly into Drupal assets
6+
# Useful for scaling Drupal and Jigs separately and hosting assets on a CDN
7+
VITE_DRUPAL_URL=/drupal
8+
VITE_ASSETS_URL=/drupal
9+
10+
# Used in the vite.config.js for configuring the /drupal path above in the Vite server
11+
VITE_FULL_DRUPAL_URL=http://localhost

Diff for: client/example.env.production

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Rename this from example.env to .env
2+
VITE_DISCORD_CLIENT_ID=PASTE_OAUTH2_CLIENT_ID_HERE
3+
4+
# Change to /drupal if you want to use vite server config
5+
# Change to blank when you're ready to bundle directly into Drupal assets
6+
# Useful for scaling Drupal and Jigs separately and hosting assets on a CDN
7+
VITE_DRUPAL_URL=
8+
VITE_ASSETS_URL=
9+
10+
# Used in the vite.config.js for configuring the /drupal path above in the Vite server
11+
# Not used if you bundle static assets directly into Drupal
12+
VITE_FULL_DRUPAL_URL=http://localhost

Diff for: client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"d3-org-chart": "^2.7.0",
5050
"gauge": "^5.0.1",
5151
"phaser": "3.55.2",
52+
"phaser-animated-tiles": "^2.0.2",
5253
"phaser3-rex-plugins": "1.1.85",
5354
"pinia": "2.0.33",
5455
"pixi.js": "^8.1.0",

Diff for: client/src/App.vue

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script>
2-
import axios from "axios";
32
import * as coreui from '@coreui/coreui'
43
import { CButton } from '@coreui/vue'
54
import { useJigsStore } from "./stores/jigs.ts";

Diff for: client/src/components/messenger/ChatBox.vue

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
</template>
99

1010
<script>
11-
import axios from 'axios';
1211
export default {
1312
name: "ChatBox",
1413
data() {

Diff for: client/src/components/pages/Inventory.vue

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import axios from "axios";
2+
import {jigsGet} from '../../utils/JigsAPI.ts';
33
import { useJigsStore } from "../../stores/jigs.ts";
44
import * as coreui from '@coreui/coreui'
55
import draggable from 'vuedraggable';
@@ -22,11 +22,6 @@ export default {
2222
},
2323
mounted() {
2424
this.jigs = useJigsStore();
25-
/* axios
26-
.get("/mystorage?_wrapper_format=drupal_ajax")
27-
.then((response) => {
28-
// this.jigs.playerStorage = response.data[0].value["playerStorage"].storeItems;
29-
}); */
3025
this.jigs.myInventory();
3126
},
3227
computed: {
@@ -42,16 +37,14 @@ export default {
4237
this.list = [{ name: "Edgard", id: id++ }];
4338
},
4439
addToStorage: function () {
45-
axios
46-
.get("/tostorage?_wrapper_format=drupal_ajax&id=" + this.jigs.item)
40+
jigsGet("tostorage?_wrapper_format=drupal_ajax&id=" + this.jigs.item)
4741
.then((response) => {
4842
this.jigs.divideInventory(response);
4943
});
5044
console.log("Storage : " + this.jigs.item);
5145
},
5246
addToBackpack: function () {
53-
axios
54-
.get("/tobackpack?_wrapper_format=drupal_ajax&id=" + this.jigs.item)
47+
jigsGet("tobackpack?_wrapper_format=drupal_ajax&id=" + this.jigs.item)
5548
.then((response) => {
5649
this.jigs.divideInventory(response);
5750
});

Diff for: client/src/components/pages/Logs.vue

-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script>
2-
import axios from "axios";
32
import { useJigsStore } from "../../stores/jigs.ts";
43
export default {
54
setup() {
@@ -31,14 +30,6 @@ export default {
3130
this.timestamp = dateTime;
3231
}
3332
}
34-
// mounted() {
35-
// this.jigs = useJigsStore();
36-
// axios
37-
// .get("/mylogs?_wrapper_format=drupal_ajax")
38-
// .then((response) => {
39-
// this.jigs.playerLogs = response.data[0].value["playerLogs"];
40-
// });
41-
// }
4233
}
4334
</script>
4435

Diff for: client/src/components/pages/Quests.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import axios from "axios";
2+
import {jigsGet} from '../../utils/JigsAPI.ts';
33
import { useJigsStore } from "../../stores/jigs.ts";
44
import * as coreui from '@coreui/coreui'
55
export default {
@@ -19,8 +19,7 @@ export default {
1919
},
2020
mounted() {
2121
this.jigs = useJigsStore();
22-
axios
23-
.get("/mymissions?_wrapper_format=drupal_ajax")
22+
jigsGet("mymissions?_wrapper_format=drupal_ajax")
2423
.then((response) => {
2524
this.jigs.playerQuests = response.data[0].value["playerMissions"];
2625
console.log(this.jigs.playerQuests)

Diff for: client/src/components/tabs/Log.vue

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<script>
2-
import axios from 'axios'
2+
import {jigsGet} from '../../utils/JigsAPI.ts';
33
export default {
44
data() {
55
return {
66
posts: []
77
}
88
},
99
mounted() {
10-
axios
11-
.get('/mydata?_wrapper_format=drupal_ajax')
10+
jigsGet('mydata?_wrapper_format=drupal_ajax')
1211
.then((response) => {
1312
this.posts = response.data[0].value
1413
})
@@ -17,10 +16,7 @@ export default {
1716
formSubmit(e) {
1817
e.preventDefault();
1918
let currentObj = this;
20-
axios.get('/mydata?_wrapper_format=drupal_ajax', {
21-
name: this.name,
22-
description: this.description
23-
})
19+
jigsGet(`mydata?_wrapper_format=drupal_ajax&name=${this.name}&description=${this.description}`)
2420
.then(function (response) {
2521
currentObj.posts = response.data[0].value
2622
})

Diff for: client/src/game/entities/layers.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class Layers {
1111
this.jigs = useJigsStore();
1212
}
1313

14-
loadLayers(scene: Phaser.Scene) {
14+
loadLayers(scene: Phaser.Scene & { animatedTiles: any; colliderMap: any; }) {
1515

1616

1717
console.log('********* load Layers *********')
@@ -35,12 +35,11 @@ console.log('********* load Layers *********')
3535
map.addTilesetImage(image);
3636
}, this);
3737

38-
// @TODO figure out why collidermap doesn't exist
39-
//scene.colliderMap = map.createLayer('Tile Layer 1', this.jigs.tilesetArray_1).setDepth(1);
38+
scene.colliderMap = map.createLayer('Tile Layer 1', this.jigs.tilesetArray_1).setDepth(1);
4039
map.createLayer('Tile Layer 2', this.jigs.tilesetArray_2).setDepth(2).setPipeline('Light2D');
4140
map.createLayer('Tile Layer 3', this.jigs.tilesetArray_3).setDepth(3).setPipeline('Light2D');
4241
map.createLayer('Tile Layer 4', this.jigs.tilesetArray_4).setDepth(5).setPipeline('Light2D');
43-
// scene.animatedTiles.init(map);
42+
scene.animatedTiles.init(map);
4443

4544
}
4645
}

Diff for: client/src/game/entities/mission.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* ------- Mission Dialog ---------
33
*/
4-
import axios from "axios";
4+
import {jigsGet} from '../../utils/JigsAPI.ts';
55
//import WebFont from '../../assets/WebFont.ts'
66

77
export default class Mission {
@@ -127,8 +127,7 @@ export default class Mission {
127127

128128
function sendPositive(data) {
129129
console.log("this is me sending a value: " + data.value);
130-
axios
131-
.get("/addmission?_wrapper_format=drupal_ajax&id=" + data.value)
130+
jigsGet("addmission?_wrapper_format=drupal_ajax&id=" + data.value)
132131
.then((response) => {
133132
console.log("this is me receiving a value: " + response);
134133
});

Diff for: client/src/game/entities/mob.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default class Mob extends Phaser.Physics.Arcade.Sprite {
1313
super(scene, 0, 0, null);
1414

1515

16-
scene.children.add(this).play('Zombie-Green-stop-default', true);
16+
scene.children.add(this).play('Zombie-Green-walk-default', true);
1717

1818
//scene.add.sprite(0, 0).play('Zombie-Green-hurt-default',true);
1919
// this.jigs = useJigsStore();

Diff for: client/src/game/entities/npc.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* -------NPC ---------
33
*/
44
import Phaser from "phaser";
5-
import axios from "axios";
5+
import {jigsGet} from '../../utils/JigsAPI.ts';
66

77
export default class Npc extends Phaser.Physics.Arcade.Sprite {
88
jigs: any;
@@ -25,8 +25,7 @@ export default class Npc extends Phaser.Physics.Arcade.Sprite {
2525
onNPCDown(npc, scene) {
2626
console.log("who" + npc);
2727
if (npc[5] == 1) {
28-
axios
29-
.get("/mymission?_wrapper_format=drupal_ajax&npc=" + npc[6])
28+
jigsGet("mymission?_wrapper_format=drupal_ajax&npc=" + npc[6])
3029
.then((response) => {
3130
console.log("why ");
3231

Diff for: client/src/game/entities/npcs.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import Npc from "./npc.ts";
55
import { useJigsStore } from '../../stores/jigs.ts';
6-
import axios from "axios";
6+
import {jigsGet} from '../../utils/JigsAPI.ts';
77

88
export default class NPCs {
99
jigs: any;
@@ -46,8 +46,7 @@ export default class NPCs {
4646
}
4747
onNPCDown(npc, self) {
4848
if (npc[5] == 1) {
49-
axios
50-
.get("/mymission?_wrapper_format=drupal_ajax&npc=" + npc[6])
49+
jigsGet("mymission?_wrapper_format=drupal_ajax&npc=" + npc[6])
5150
.then((response) => {
5251
console.log("");
5352
self.scene.hydrateMission(response);

0 commit comments

Comments
 (0)