Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/moddio/taro into videochat
Browse files Browse the repository at this point in the history
  • Loading branch information
parthvakharia committed Feb 10, 2021
2 parents 06f1eac + 5237098 commit 0f41f08
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 37 deletions.
11 changes: 6 additions & 5 deletions engine/components/chat/IgeChatComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,25 @@ var IgeChatComponent = IgeEventingClass.extend({
sendChatMessage: function () {

if (ige.isClient) {
var player = ige.client.myPlayer;
var gameData = ige.game && ige.game.data && ige.game.data.defaultData;
var message = $("#message").val();

// set character limit to 100 characters
if (message.length > 80)
message = message.substr(0, 80);
var player = ige.client.myPlayer;
if (player && player._stats.banChat) {
//dont send chat message if player is ban

//don't send chat message if user is ban or unverified.
if (player && (player._stats.banChat || (gameData && gameData.allowVerifiedUserToChat && !player._stats.isUserVerified))) {
// don't send message
}
else {
ige.network.send('igeChatMsg', { "text": message, "roomId": "1" });
}
$("#message").blur();
$("#message").val("");
$('#chat-message-input').hide();

}

},

escapeOutput: function(str) {
Expand Down
7 changes: 4 additions & 3 deletions engine/components/chat/IgeChatServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ var IgeChatServer = {
ige.devLog('chat - sendToRoom: ' + message);

var self = ige.chat;
// dont send message if player is ban from sending message
var player = ige.game.getPlayerByClientId(from);
var gameData = ige.game.data && ige.game.data.defaultData;
if (from && player && player._stats) {
if (player._stats.banChat) {
// don't send message if player is ban from sending message or unverified
if (player._stats.banChat || (gameData && gameData.allowVerifiedUserToChat && !player._stats.isUserVerified)) {
return;
} else if (this.isSpamming(from, message)) {
// permanently mute player from this game;
Expand All @@ -76,7 +77,7 @@ var IgeChatServer = {
}
ige.network.send('igeChatMsg', msg, from);
ige.clusterClient.banChat({
gameId: ige.game.data.defaultData._id,
gameId: gameData._id,
userId: player._stats.userId
});
return;
Expand Down
21 changes: 18 additions & 3 deletions engine/core/IgeEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ var IgeEngine = IgeEntity.extend({
//this._idCounter = 0
this.sanitizer = require('sanitizer').sanitize;
this.emptyTimeLimit = 5 * 60 * 1000; // in ms
this.startedAt = new Date()
this.lastCheckedAt = Date.now();
}

Expand Down Expand Up @@ -175,6 +174,14 @@ var IgeEngine = IgeEntity.extend({
return lifeSpan;
},

getIdleTimeoutMs: function () {
var defaultValue = 5;
var idleTimeoutHours = ige.server.tier == '0' ? ige.game.data.defaultData.privateServerIdleTimeout : 0;
var timeoutMins = idleTimeoutHours ? idleTimeoutHours * 60 : defaultValue;

return timeoutMins * 60 * 1000;
},

/**
* Returns an object from the engine's object register by
* the object's id. If the item passed is not a string id
Expand Down Expand Up @@ -960,6 +967,7 @@ var IgeEngine = IgeEntity.extend({
}

if (ige.isServer) {
this.emptyTimeLimit = this.getIdleTimeoutMs();
requestAnimFrame(ige.engineStep);
}

Expand Down Expand Up @@ -2099,6 +2107,7 @@ var IgeEngine = IgeEntity.extend({
var playerCount = ige.$$('player').filter(function (player) { return player._stats.controlledBy == 'human' }).length;

if (playerCount <= 0) {
console.log('self.emptyTimeLimit', self.emptyTimeLimit);
if (!self.serverEmptySince) {
self.serverEmptySince = self.now;
}
Expand All @@ -2114,13 +2123,19 @@ var IgeEngine = IgeEntity.extend({
var lifeSpan = self.getLifeSpan();

// if server's lifeSpan is over, kill it (e.g. kill server after 5 hours)
var age = self.now - self.startedAt;
var age = self.now - ige.server.gameStartedAt;

var shouldLog = ige.server.logTriggers && ige.server.logTriggers.timerLogs;
if (shouldLog) {
console.log(self.now, self.startedAt, age, lifeSpan, age > lifeSpan);
console.log(self.now, ige.server.gameStartedAt, age, lifeSpan, age > lifeSpan);
}
if (age > lifeSpan) {
console.log({
lifeSpan,
age,
now: self.now,
startedAt: ige.server.gameStartedAt
});
ige.server.kill("server lifespan expired " + lifeSpan);
}
}
Expand Down
8 changes: 4 additions & 4 deletions server/ServerNetworkEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,14 @@ var ServerNetworkEvents = {
fromItem._stats.controls.permittedInventorySlots == undefined ||
fromItem._stats.controls.permittedInventorySlots.length == 0 ||
fromItem._stats.controls.permittedInventorySlots.includes(data.to + 1) ||
data.to + 1 > unit._stats.inventorySize // any item can be moved into backpack slots
(data.to + 1 > unit._stats.inventorySize && fromItem._stats.controls.backpackAllowed == true) // any item can be moved into backpack slots if the backpackAllowed property is true
) &&
(
toItem._stats.controls == undefined ||
toItem._stats.controls.permittedInventorySlots == undefined ||
toItem._stats.controls.permittedInventorySlots.length == 0 ||
toItem._stats.controls.permittedInventorySlots.includes(data.from + 1) ||
data.from + 1 > unit._stats.inventorySize // any item can be moved into backpack slots
(data.from + 1 > unit._stats.inventorySize && toItem._stats.controls.backpackAllowed == true) // any item can be moved into backpack slots if the backpackAllowed property is true
)
) {
fromItem.streamUpdateData([{ slotIndex: parseInt(data.to) }]);
Expand All @@ -513,7 +513,7 @@ var ServerNetworkEvents = {
fromItem._stats.controls.permittedInventorySlots == undefined ||
fromItem._stats.controls.permittedInventorySlots.length == 0 ||
fromItem._stats.controls.permittedInventorySlots.includes(data.to + 1) ||
data.to + 1 > unit._stats.inventorySize // any item can be moved into backpack slots
(data.to + 1 > unit._stats.inventorySize && fromItem._stats.controls.backpackAllowed == true) // any item can be moved into backpack slots if the backpackAllowed property is true
)
) {
fromItem.streamUpdateData([{ slotIndex: parseInt(data.to) }]);
Expand Down Expand Up @@ -666,7 +666,7 @@ var ServerNetworkEvents = {

_onPlayerCustomInput: function (data, clientId) {
var player = ige.game.getPlayerByClientId(clientId)
if (player) {
if (player && data && data.status === 'submitted') {
player.lastCustomInput = data.inputText
ige.trigger.fire("playerCustomInput", { playerId: player.id() })
}
Expand Down
16 changes: 11 additions & 5 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ var Server = IgeClass.extend({
},

// run a specific game in this server
startGame: function () {
startGame: function (gameJson) {
console.log("ige.server.startGame()")
var self = this;

Expand Down Expand Up @@ -396,12 +396,16 @@ var Server = IgeClass.extend({
domain = global.beUrl;
}

var gameUrl = domain + "/api/game-client/" + ige.server.gameId + '/?source=gs';

console.log("connecting to BE:", global.beUrl)
console.log("gameUrl", gameUrl)

var promise;
if (ige.server.gameId) {

if (gameJson) {
promise = Promise.resolve(gameJson);
}
else if (ige.server.gameId) {
var gameUrl = domain + "/api/game-client/" + ige.server.gameId + '/?source=gs';
console.log("gameUrl", gameUrl)
promise = self.loadGameJSON(gameUrl);
} else {
promise = new Promise(function (resolve, reject) {
Expand All @@ -418,8 +422,10 @@ var Server = IgeClass.extend({
resolve(data);
});
}

promise.then((game) => {
ige.addComponent(GameComponent)
self.gameStartedAt = new Date();

ige.game.data = game.data
ige.game.cspEnabled = !!ige.game.data.defaultData.clientSidePredictionEnabled;
Expand Down
2 changes: 1 addition & 1 deletion src/gameClasses/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ var Player = IgeEntity.extend({
// if (ige.mobileControls && !ige.mobileControls.isMobile) {
// $("#dev-console").show() // if user has access of this game, show dev console
// }
$('#game-suggestions-card').removeClass('d-xl-block');
// $('#game-suggestions-card').removeClass('d-xl-block');
// $("#invite-players-card").show();
$("#toggle-dev-panels").show();
$("#kick-player").show();
Expand Down
6 changes: 5 additions & 1 deletion src/gameClasses/Unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,11 @@ var Unit = IgeEntityBox2d.extend({
this._stats.controls && this._stats.controls.mouseBehaviour.rotateToFaceMouseCursor &&
this._stats.currentBody && !this._stats.currentBody.fixedRotation
) {
self.rotateTo(0, 0, self.angleToTarget);
if(this._stats.controls.absoluteRotation){
self.rotateTo(0, 0, ownerPlayer.absoluteAngle);
}else{
self.rotateTo(0, 0, self.angleToTarget);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/gameClasses/components/GameComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var GameComponent = IgeEntity.extend({
isEmailVerified: data.isEmailVerified,
banChat: data.banChat,
mutedUsers: data.mutedUsers,
isUserVerified: data.isUserVerified,
};

var player = new Player(playerData);
Expand Down
23 changes: 16 additions & 7 deletions src/gameClasses/components/MobileControlsComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ var MobileControlsComponent = IgeEntity.extend({

if (key == 'movementWheel'){
let moveStick = new Joystick({
outer: PIXI.Sprite.from('https://cache.modd.io/asset/spriteImage/1609245667104_joystick.png?version=123', { crossOrigin: true }),
inner: PIXI.Sprite.from('https://cache.modd.io/asset/spriteImage/1609244919482_joystick-handle.png?version=123', { crossOrigin: true }),
outerScale: { x: 0.8, y:0.8 },
outerScale: { x: 1.2, y:1.2 },
innerScale: { x: 0.5, y:0.5 },
onChange: (data) => {

Expand Down Expand Up @@ -450,10 +448,21 @@ var MobileControlsComponent = IgeEntity.extend({
newButton.y = y;
newButton._key = key.toLowerCase();

var label = new PIXI.Text(text, { fontFamily: 'Arial', fontSize: 24, fill: 0xffffff, align: 'center' });
ige.pixi.mobileControls.addChild(label);
label.anchor.set(0.5);
label.position.set(x+(w / 2), y+(h / 2));
var iconUrl = null;
if (text == "BUTTON1") iconUrl = "https://cache.modd.io/asset/spriteImage/1610494864771_fightFist_circle.png";

if (iconUrl){
var icon = new PIXI.Sprite.from(iconUrl, { crossOrigin: true });
ige.pixi.mobileControls.addChild(icon);
icon.scale.set(0.5);
icon.anchor.set(0.5);
icon.position.set(x+(w / 2), y+(h / 2));
} else {
var label = new PIXI.Text(text, { fontFamily: 'Arial', fontSize: 24, fill: 0xffffff, align: 'center' });
ige.pixi.mobileControls.addChild(label);
label.anchor.set(0.5);
label.position.set(x+(w / 2), y+(h / 2));
}

newButton.isButton = true;
newButton.interactive = true;
Expand Down
4 changes: 2 additions & 2 deletions src/gameClasses/components/script/ActionComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,8 @@ var ActionComponent = IgeEntity.extend({
break;

case 'setItemFireRate':
var item = ige.variable.getValue(action.entity, vars)
var value = ige.variable.getValue(action.value, vars)
var item = ige.variable.getValue(action.item, vars)
var value = ige.variable.getValue(action.number, vars)

if (item && item._category == 'item') {
item.streamUpdateData([{ fireRate: value }]);
Expand Down
6 changes: 6 additions & 0 deletions src/gameClasses/components/script/VariableComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,12 @@ var VariableComponent = IgeEntity.extend({
}

break;

case 'getTimeString':
var seconds = self.getValue(text.seconds, vars);

returnValue = new Date(parseFloat(seconds) * 1000).toISOString().substr(11, 8)
break;

case 'getValueOfEntityVariable':
var variableData = self.getValue(text.variable, vars);
Expand Down
8 changes: 4 additions & 4 deletions src/gameClasses/components/ui/MenuUiComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ var MenuUiComponent = IgeEntity.extend({
},
toggleGameSuggestionCard: function (show) {
if (show) {
$('#game-suggestions-card').removeClass('d-xl-none');
$('#game-suggestions-card').addClass('d-xl-block');
// $('#game-suggestions-card').removeClass('d-xl-none');
// $('#game-suggestions-card').addClass('d-xl-block');
}
else {
$('#game-suggestions-card').removeClass('d-xl-block');
$('#game-suggestions-card').addClass('d-xl-none');
// $('#game-suggestions-card').removeClass('d-xl-block');
// $('#game-suggestions-card').addClass('d-xl-none');
}
},
startLoading: function () {
Expand Down
10 changes: 8 additions & 2 deletions src/gameClasses/components/ui/PlayerUiComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ var PlayerUiComponent = IgeEntity.extend({
});

$('#player-input-modal').on('shown.bs.modal', function () {
$("#player-input-field").focus();
if (self.isDismissibleInputModalShown) {
$("#player-input-cancel").focus();
}
else {
$("#player-input-field").focus();
}
});

$('button#player-input-submit').on('click', function () {
Expand All @@ -47,7 +52,7 @@ var PlayerUiComponent = IgeEntity.extend({
});

$('button#player-input-cancel').on('click', function () {
self.pressedButton = true;
self.pressedButton = false;
ige.network.send('playerCustomInput', { status: 'cancelled' });
$('#player-input-modal').modal('hide');
});
Expand Down Expand Up @@ -132,6 +137,7 @@ var PlayerUiComponent = IgeEntity.extend({
var self = this;

config.isDismissible = config.isDismissible === undefined ? true : !!(config.isDismissible);
self.isDismissibleInputModalShown = config.isDismissible;

$('#player-input-field-label').html(config.fieldLabel || 'Field');
$('#player-input-field').val('');
Expand Down

0 comments on commit 0f41f08

Please sign in to comment.