197 lines
6.4 KiB
JavaScript
197 lines
6.4 KiB
JavaScript
const logindb = {
|
|
loginplayer:[{username:'testuser',password:'testpwd'}]
|
|
}
|
|
var loginusername=''
|
|
var loginpassword=''
|
|
function addItemToMarketTable(item,price){
|
|
let table = document.getElementById('balanceitems')
|
|
let tr=document.createElement('tr')
|
|
let tditem=document.createElement('td')
|
|
tditem.innerHTML=item
|
|
let tdprice=document.createElement('td')
|
|
tdprice.innerHTML=price
|
|
tr.appendChild(tditem)
|
|
tr.appendChild(tdprice)
|
|
table.appendChild(tr)
|
|
}
|
|
function addPlayerToLBTable(player,index){
|
|
let table = document.getElementById('playerlb')
|
|
let tr=document.createElement('tr')
|
|
let tditem=document.createElement('td')
|
|
tditem.innerHTML=player
|
|
let tdindex=document.createElement('td')
|
|
tdindex.innerHTML=index
|
|
tr.appendChild(tditem)
|
|
tr.appendChild(tdindex)
|
|
table.appendChild(tr)
|
|
}
|
|
function addGuildToLBTable(guild,index){
|
|
let table = document.getElementById('guildlb')
|
|
let tr=document.createElement('tr')
|
|
let tditem=document.createElement('td')
|
|
tditem.innerHTML=guild
|
|
let tdindex=document.createElement('td')
|
|
tdindex.innerHTML=index
|
|
tr.appendChild(tditem)
|
|
tr.appendChild(tdindex)
|
|
table.appendChild(tr)
|
|
}
|
|
function createDashBox(color,title=null){
|
|
let dashBox = document.createElement('div')
|
|
dashBox.className='dash-full-box'
|
|
dashBox.id=color
|
|
if(title!=null){
|
|
let dashtitle = document.createElement('p')
|
|
dashtitle.className='dash-title'
|
|
dashtitle.innerText=title
|
|
dashBox.appendChild(dashtitle)
|
|
}
|
|
document.getElementById('dashboardcontent').appendChild(dashBox)
|
|
let br= document.createElement('br')
|
|
document.getElementById('dashboardcontent').appendChild(br)
|
|
return dashBox
|
|
}
|
|
function spawnBaseDashBox(){
|
|
let wdmbox = createDashBox('red')
|
|
wdmbox.innerHTML=`<div class=fullcentered>
|
|
<button id="withdrawalbutton" name="withdrawalbutton">Immediate Withdrawal</button>
|
|
</div>`
|
|
let mobox = createDashBox('green','MONEY INFOS:')
|
|
mobox.innerHTML = `
|
|
<p><b>Your Current balance: </b><span id="playermoney">NODATA</span>$</p>
|
|
<p><b>Current balance of your Guild: </b><span id=guildmoney>NODATA</span>$</p>`
|
|
let markbox = createDashBox('yellow','TRADE INFOS:')
|
|
markbox.innerHTML=`<b>Market price of items:</b>
|
|
<div class="tablecontainer">
|
|
<table >
|
|
<thead>
|
|
<th>
|
|
Items:
|
|
</th>
|
|
<th>
|
|
Price:
|
|
</th>
|
|
</thead>
|
|
<tbody id="balanceitems">
|
|
</tbody>
|
|
</table>
|
|
</div>`
|
|
let lbbox = createDashBox('orange','LEADERBOARD:')
|
|
lbbox.innerHTML=`<div class="tablecontainer">
|
|
<table>
|
|
<thead>
|
|
<th>
|
|
Player:
|
|
</th>
|
|
<th>
|
|
Place:
|
|
</th>
|
|
</thead>
|
|
<tbody id="playerlb">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="tablecontainer">
|
|
<table>
|
|
<thead>
|
|
<th>
|
|
Guild:
|
|
</th>
|
|
<th>
|
|
Place:
|
|
</th>
|
|
</thead>
|
|
<tbody id="guildlb">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
`
|
|
|
|
}
|
|
function loadscript(){
|
|
createauth()
|
|
}
|
|
window.onload=loadscript
|
|
function startscript(){
|
|
if(auth(loginusername,loginpassword)){
|
|
mainscript(loginusername,loginpassword)
|
|
}
|
|
}
|
|
function mainscript(username,password){
|
|
spawnBaseDashBox()
|
|
showGameDatas(username,password)
|
|
}
|
|
function createauth(){
|
|
document.getElementById('dashboardcontent').innerHTML=`<div id=logindiv id=logindiv><div id=loginindic style="background-color:red; color:white"></div><input type=text id=loginusername placeholder="Your UserName"><br><input type=password id=loginpassword placeholder="Your PassWord"><br><button onclick="loginsubmit()">Se connecter</button></div>`
|
|
}
|
|
function loginsubmit(){
|
|
loginusername = document.getElementById('loginusername').value
|
|
loginpassword = document.getElementById('loginpassword').value
|
|
startscript()
|
|
}
|
|
function auth(username,password){
|
|
if(checkauth(username,password)){
|
|
document.getElementById('logindiv').remove()
|
|
return true
|
|
}
|
|
else{
|
|
document.getElementById('loginindic').innerHTML='Bad Password or Username'
|
|
return false
|
|
}
|
|
}
|
|
function checkauth(username, password){
|
|
const [check, index] = checkusername(username)
|
|
if(check){
|
|
if(logindb.loginplayer[index].password===password){
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
function checkusername(username){
|
|
for(let i=0; i<logindb.loginplayer.length;i++){
|
|
if(username===logindb.loginplayer[i].username){
|
|
return [true , i]
|
|
}
|
|
}
|
|
return [false , null]
|
|
}
|
|
|
|
function fetchGameDatas(username,password){
|
|
//fetch: return this normally
|
|
let gamedatas = {
|
|
playermoney:999999,
|
|
guildmoney:999999999999,
|
|
itemprice:[['Uranium',299],['EpicRubadium',599],['SuperExoticalFractalium',99999],['Iron',50],['Wood',20],['Steak',10],['Apple',5]],
|
|
playerlb:['TheBestUser','TheSecondUser','ThethirdUser','hello','world','how','are','you','men'],
|
|
guildlb:['BestGuild','SecondGuild','ThirdGuild','vote','for','the','best','guild','that','is','adminGuild!!!'],
|
|
playerusername:'testuser',
|
|
playerpicture:'https://cdn.discordapp.com/avatars/917123777488384021/d3a5dbeb89d98da26f30b061156e6868.webp?size=128'
|
|
}
|
|
return gamedatas //else if error return null
|
|
}
|
|
function showGameDatas(username,password){
|
|
let gamedatas = fetchGameDatas(username,password)
|
|
if(gamedatas!=null){
|
|
gid('playermoney').innerHTML=gamedatas.playermoney
|
|
gid('guildmoney').innerHTML=gamedatas.guildmoney
|
|
for(let i =0; i< gamedatas.itemprice.length;i++){
|
|
addItemToMarketTable(gamedatas.itemprice[i][0],gamedatas.itemprice[i][1])
|
|
}
|
|
for(let i=0;i<gamedatas.guildlb.length;i++){
|
|
addGuildToLBTable(gamedatas.guildlb[i],i)
|
|
}
|
|
for(let i = 0; i<gamedatas.playerlb.length;i++){
|
|
addPlayerToLBTable(gamedatas.playerlb[i],i)
|
|
}
|
|
gid('playername').innerHTML=gamedatas.playerusername
|
|
gid('playerpicture').src=gamedatas.playerpicture
|
|
}
|
|
}
|
|
function gid(id){
|
|
return document.getElementById(id)
|
|
}
|
|
function withdrawal(){
|
|
alert('Order Send, you\'re troops back home to your base')
|
|
}
|
|
document.getElementById('withdrawalbutton').addEventListener('click',withdrawal)
|