-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrooms.js
More file actions
167 lines (152 loc) · 5.86 KB
/
rooms.js
File metadata and controls
167 lines (152 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyB2kMCF_wglD3NPBDjSl6phkYrorRI1LgE",
authDomain: "minecraft-world-community.firebaseapp.com",
databaseURL: "https://minecraft-world-community-default-rtdb.firebaseio.com",
projectId: "minecraft-world-community",
storageBucket: "minecraft-world-community.appspot.com",
messagingSenderId: "79164899563",
appId: "1:79164899563:web:36388146fef46073c63eae"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
logoutBox = new Infobox("Logout","Want to logout?","exitdoor.webp","Log-Out","confirmedLogout()","cancelLogout()","white","lime");
//load user
gamemode = "survival";
function loadUser() {
user = localStorage.getItem("user");
userPass = localStorage.getItem("pass");
if (user == undefined) {
window.location = "index.html";
}
getUserData()
}
function showOptions(option) {
if (option == 1) {
document.getElementById("RoomOptions").innerHTML = "<div><input placeholder='search room' id='roomSearch' class='MCInput'><button class='mc-do-button' onclick='searchRoom()'>Search</button></div><p id='addOutput'></p>";
} else if (option == 2) {
document.getElementById("RoomOptions").innerHTML = "<div class='form-group input_div_room_page' title='Add a room'><label>Add a new Minecraft Room:</label><br><input type='text' id='roomName' placeholder='#room' class='MCInput'><button class='MCButton' style='background-color: rgb(233, 79, 8);' onclick='selectGamemode()'id='gamemode'>survival</button></div><button onclick='addRoom();' class='mc-do-button'>Add Room</button><p id='addOutput'></p>"
}
}
function userUi(){
window.location = "Steve.html";
}
function searchRoom() {
searchData = document.getElementById("roomSearch").value;
if (!searchData == "") {
var searchref = firebase.database().ref(searchData + "/purpose");
var isRoomCreated;
var isJoining = false;
searchref.on("value", data => {
isRoomCreated = data.val();
console.log(isRoomCreated);
if (!isJoining) {
isJoining = true;
if (isRoomCreated == searchData + " - Gamemode: survival" || isRoomCreated == searchData + " - Gamemode: creative") {
localStorage.setItem("room", searchData);
window.location = "MinecraftPage.html";
} else {
document.getElementById("addOutput").innerHTML = "Could not find room";
}
}
});
} else {
document.getElementById("addOutput").innerHTML = "Can not join a room without name";
}
}
function selectGamemode() {
if (gamemode == "survival") {
gamemode = "creative";
document.getElementById("gamemode").innerHTML = gamemode;
document.getElementById("gamemode").style.backgroundColor = "rgb(61, 221, 21)";
} else {
gamemode = "survival"
document.getElementById("gamemode").innerHTML = gamemode;
document.getElementById("gamemode").style.backgroundColor = "rgb(233, 79, 8)";
}
console.log(gamemode);
}
function addRoom() {
roomName = document.getElementById("roomName").value;
if(roomName == "users"){
document.getElementById("addOutput").innerHTML = "Room Name error!";
}else{
if (!roomName == "") {
var roomref = firebase.database().ref(roomName + "/purpose");
var isRoomCreated;
var isJoining = false;
roomref.on("value", data => {
isRoomCreated = data.val();
console.log(isRoomCreated);
if (!isJoining) {
isJoining = true;
if (isRoomCreated == null) {
sm = roomName + " - Gamemode: " + gamemode;
firebase.database().ref("/").child(roomName).update({
purpose: roomName + " - Gamemode: " + gamemode
});
localStorage.setItem("room", roomName);
window.location = "MinecraftPage.html";
} else {
document.getElementById("addOutput").innerHTML = "Room Already exixts";
}
}
});
} else {
document.getElementById("addOutput").innerHTML = "Room name can not be empty";
}
}
}
function getData() {
firebase.database().ref("/").on('value', function (snapshot) {
document.getElementById("output").innerHTML = "";
snapshot.forEach(function (childSnapshot) {
childKey = childSnapshot.key;
if (childKey != "users") {
roomNames = childKey;
console.log("Room - " + roomNames);
row = "<div class='roomName' id=" + roomNames + " onclick='redirectToRoomName(this.innerHTML)'>" + roomNames + "</div><br><br>";
document.getElementById("output").innerHTML += row;
}
});
});
}
getData();
function getUserData() {
document.getElementById("userName").innerHTML = user;
firebase.database().ref("/users/" + user + "/userImg").on('value', data => {
ThisImage = data.val();
UserImage = ThisImage;
if (UserImage == "creeper") {
document.getElementById("userPicture").src = "UserCreeper.png";
} else if (UserImage == "enderman") {
document.getElementById("userPicture").src = "UserEnderman.png";
} else if (UserImage == "zombie") {
document.getElementById("userPicture").src = "UserZombie.png";
} else if (UserImage == "steve") {
document.getElementById("userPicture").src = "UserSteve.png";
} else if (UserImage == "pig") {
document.getElementById("userPicture").src = "UserPig.png";
}
})
firebase.database().ref("/users/" + user + "/password").on('value', data => {
password = data.val();
if(password != userPass){
window.location = "index.html";
}
})
}
function redirectToRoomName(name) {
console.log(name);
localStorage.setItem("room", name);
window.location = "MinecraftPage.html";
}
function logout() {
logoutBox.open();
}
function confirmedLogout(){
window.location = "index.html";
}
function cancelLogout(){
logoutBox.close();
}