Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/junon-common/protocol/base.proto
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ message ServerChat {
string username = 3;
string uid = 4;
bool isTeam = 5;
string prefixesList = 6;
}

message Chunk {
Expand Down
24 changes: 24 additions & 0 deletions packages/junon-io/client/main.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,11 @@
<td>value1, value2, ... , valueN</td>
<td>Sums all given values. Ex. $add(2,5,8) = 15</td>
</tr>
<tr>
<td class='function_name'>$if</td>
<td>value1, operator, value2, then, else</td>
<td>Returns the value given the condition.</td>
</tr>
<tr>
<td class='function_name'>$subtract</td>
<td>value1, value2, ... , valueN</td>
Expand Down Expand Up @@ -1041,6 +1046,16 @@
<td>$itemId</td>
<td>Returns the usage capacity of an item</td>
</tr>
<tr>
<td class="function_name">$getNthLetter</td>
<td>index, word</td>
<td>Returns the Nth letter of a word</td>
</tr>
<tr>
<td class="function_name">$getNthWord</td>
<td>index, string</td>
<td>Returns the Nth word of a string</td>
</tr>
</table>
</div>
<div>
Expand Down Expand Up @@ -1922,6 +1937,15 @@
<label for='disable_fire_spread'><%= t('No') %></label>
</div>
</div>
<div class="colony_info_entry is_spectate_enabled">
<label><%= t('Allow Spectate Command') %></label>
<div class='colony_info_entry_radio_container'>
<input type="radio" id="enable_spectate" name='is_spectate_enabled' value='yes'>
<label for='enable_spectate'><%= t('Yes') %></label>
<input type="radio" id="disable_spectate" name='is_spectate_enabled' value='no'>
<label for='disable_spectate'><%= t('No') %></label>
</div>
</div>
</div>

<div class='colony_logs_container colony_tab_content' data-tab='logs'>
Expand Down
15 changes: 10 additions & 5 deletions packages/junon-io/client/src/menus/chat_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ class ChatMenu extends BaseMenu {
tooltip.style.top = top + "px"
}


createChatEntry(chatGroup, messageObj) {
createChatEntry(chatGroup, messageObj,prefixList) {
let chatMessage = document.createElement("div")
chatMessage.className = "chat_message"
chatMessage.dataset.username = messageObj.username
Expand All @@ -229,7 +228,11 @@ class ChatMenu extends BaseMenu {
let chatUsername = document.createElement("span")
chatUsername.className = "chat_user"
if (messageObj.username) {
chatUsername.innerText = "[" + messageObj.username + "]"
if (prefixList && prefixList[messageObj.username]) {
chatUsername.innerHTML = "<span style='color:"+ prefixList[messageObj.username].color +";'>"+ prefixList[messageObj.username].styleA + prefixList[messageObj.username].prefix.slice(0, 16) + prefixList[messageObj.username].styleB + "</span> [" + messageObj.username + "]"
} else {
chatUsername.innerText = "[" + messageObj.username + "]"
}
if (messageObj.uid) {
chatUsername.dataset.uid = messageObj.uid
}
Expand Down Expand Up @@ -261,6 +264,8 @@ class ChatMenu extends BaseMenu {
}
}



setOpenDisplay() {
this.el.style.display = 'inline-block'
}
Expand All @@ -275,7 +280,7 @@ class ChatMenu extends BaseMenu {
const playerId = data.playerId
const username = data.username
const message = data.message

const prefixList = JSON.parse(data.prefixesList||"{}")
const chatUser = this.game.sector.players[playerId]

let messageObj = this.parseServerChat(message)
Expand All @@ -285,7 +290,7 @@ class ChatMenu extends BaseMenu {
let chatGroup = data.isTeam ? "team" : "local"

if (!this.isMuted(username)) {
this.createChatEntry(chatGroup, messageObj)
this.createChatEntry(chatGroup, messageObj, prefixList)
}

if (chatUser && !this.isMuted(chatUser.name)) {
Expand Down
40 changes: 39 additions & 1 deletion packages/junon-io/client/src/menus/team_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class TeamMenu extends BaseMenu {
this.el.querySelector("#enable_fov").addEventListener("click", this.onEnableFovClick.bind(this), true)
this.el.querySelector("#disable_fov").addEventListener("click", this.onDisableFovClick.bind(this), true)

this.el.querySelector("#enable_spectate").addEventListener("click", this.onAllowSpectateClick.bind(this), true)
this.el.querySelector("#disable_spectate").addEventListener("click", this.onDenySpectateClick.bind(this), true)

this.el.querySelector("#enable_minimap").addEventListener("click", this.onEnableMinimapClick.bind(this), true)
this.el.querySelector("#disable_minimap").addEventListener("click", this.onDisableMinimapClick.bind(this), true)

Expand Down Expand Up @@ -143,6 +146,15 @@ class TeamMenu extends BaseMenu {
this.el.querySelector("#disable_fov").checked = true
}
}

if (name === 'isSpectateAllowed') {
let value = settings[name]
if (value) {
this.el.querySelector("#enable_spectate").checked = true
} else {
this.el.querySelector("#disable_spectate").checked = true
}
}

if (name === 'showMiniMap') {
let value = settings[name]
Expand Down Expand Up @@ -405,7 +417,6 @@ class TeamMenu extends BaseMenu {
})
}
}

onDisableFovClick(e) {
e.preventDefault()

Expand All @@ -420,6 +431,33 @@ class TeamMenu extends BaseMenu {
}
}

onAllowSpectateClick(e) {
e.preventDefault()

let value = e.target.value
if (value === 'yes') {
SocketUtil.emit("SectorAction", {
action: 'editSetting',
sectorId: this.game.sector.uid,
key: 'isSpectateAllowed',
value: 'true'
})
}
}
onDenySpectateClick(e) {
e.preventDefault()

let value = e.target.value
if (value === 'no') {
SocketUtil.emit("SectorAction", {
action: 'editSetting',
sectorId: this.game.sector.uid,
key: 'isSpectateAllowed',
value: 'false'
})
}
}

onEnableFloorAutodirtClick(e) {
e.preventDefault()

Expand Down
65 changes: 65 additions & 0 deletions packages/junon-io/server/commands/chatprefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const BaseCommand = require("./base_command")
const Constants = require("../../common/constants")

class ChatPrefix extends BaseCommand {

getUsage() {
return [
"/chatprefix set [player] [prefix] [color] [style]",
"/chatprefix clear [player]",
"Styles:",
"1: [Test], 2: (Test), 3: {Test}",
]
}

allowOwnerOnly() {
return true
}

perform(caller, args) {
if (!this.game.playerChatPrefixes) {this.game.playerChatPrefixes = {}}
let selectedPlayers = this.getPlayersBySelector(args[1])
if (selectedPlayers.length === 0) {
caller.showChatError("No such player")
return
}

let subcommand = args[0]
let style = args[4]
if (style) {
if (style==1) {
style = "[]"
} else if (style==2) {
style = "()"
} else {
style = "{}"
}
} else {style="[]"}

switch(subcommand) {
case "set":
if (!args[2]) {
caller.showChatError("No prefix")
return
}
selectedPlayers.forEach(ply => {
console.log(ply.name)
this.game.playerChatPrefixes[ply.name] = {
prefix:args[2].replace(/[^a-zA-Z]/g, '').slice(0, 8),
color:args[3] || "#ffffff",
styleA:style[0],
styleB:style[1]
}
});
break
case "clear":
selectedPlayers.forEach(ply => {
delete this.game.playerChatPrefixes[ply.name]
})
break
}
}

}

module.exports = ChatPrefix
13 changes: 10 additions & 3 deletions packages/junon-io/server/commands/fly.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ class Fly extends BaseCommand {

getUsage() {
return [
"Enables or disables fly state for players.",
"/fly",
"/fly [player]"
"/fly [player]",
"/fly [player] [true/false]"
]
}

Expand All @@ -20,17 +22,22 @@ class Fly extends BaseCommand {

perform(player, args) {
const username = args[0]
let nextState = args[1]

if ((nextState !== "true") && (nextState !== "false") && (nextState !== null)) {
nextState = null
}

let targetPlayers = this.getPlayersBySelector(username)
if (targetPlayers.length === 0) {
if (player.isPlayer()) {
player.toggleFly()
player.toggleFly(nextState)
}
return
}

targetPlayers.forEach((targetPlayer) => {
targetPlayer.toggleFly()
targetPlayer.toggleFly(nextState)
})
}

Expand Down
31 changes: 24 additions & 7 deletions packages/junon-io/server/commands/god.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const Protocol = require('../../common/util/protocol')
class God extends BaseCommand {
getUsage() {
return [
"Enables or disables god state for players.",
"/god",
"/god [player]"
"/god [player]",
"/god [player] [true/false]"
]
}

Expand All @@ -21,6 +23,12 @@ class God extends BaseCommand {

perform(caller, args) {
const selector = args[0]
let godPar = args[1]

if ((godPar !== "false") && (godPar !== "true") && (godPar !== null)) {
godPar = null
}

if (selector) {
if (!caller.isSectorOwner()) {
caller.showChatError("permission denied")
Expand All @@ -34,21 +42,30 @@ class God extends BaseCommand {
}

targetPlayers.forEach((player) => {
this.toggleGod(player)
this.toggleGod(player,godPar)
})
} else {
if (caller.isPlayer()) {
this.toggleGod(caller)
if (caller.isPlayer()) {
this.toggleGod(caller,godPar)
}
}
}

toggleGod(player) {
player.godMode = !player.godMode
toggleGod(player,tostate) {

if (tostate) {
if (tostate == "true") {
player.godMode = true
} else {
player.godMode = false
}
} else {
player.godMode = !player.godMode
}

if (player.godMode) {
player.setHealth(player.getMaxHealth())
}

player.showChatSuccess("god mode: " + (player.godMode ? "ON" : "OFF" ))
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/junon-io/server/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Commands.dirt = require('./dirt')
Commands.blood = require('./blood')
Commands.setstatus = require('./set_status')
Commands.menu = require('./menu')
Commands.chatprefix = require('./chatprefix')

Commands.accept_rules = require("./accept_rules")

Expand Down
3 changes: 3 additions & 0 deletions packages/junon-io/server/commands/spectate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const BaseCommand = require("./base_command")
const Constants = require("../../common/constants")
const Protocol = require('../../common/util/protocol')
const { setting } = require(".")

class Spectate extends BaseCommand {
getUsage() {
Expand Down Expand Up @@ -36,10 +37,12 @@ class Spectate extends BaseCommand {
this.toggleSpectate(player)
})
} else {
if (this.game.sector.settings.isSpectateAllowed) {
if (caller.isPlayer()) {
this.toggleSpectate(caller)
}
}
}

}

Expand Down
Loading