Initial commit

This commit is contained in:
abrendan
2023-11-30 14:15:19 +00:00
commit e4599df811
5457 changed files with 500139 additions and 0 deletions

39
index.js Normal file
View File

@@ -0,0 +1,39 @@
const http = require("http");
const express = require("express");
const socketio = require("socket.io");
const path = require("path");
const app = express();
const httpserver = http.Server(app);
const io = socketio(httpserver);
const gamedirectory = path.join(__dirname, "html");
app.use(express.static(gamedirectory));
httpserver.listen(3000);
var rooms = [];
var usernames = [];
io.on('connection', function(socket){
socket.on("join", function(room, username){
if (username != ""){
rooms[socket.id] = room;
usernames[socket.id] = username;
socket.leaveAll();
socket.join(room);
io.in(room).emit("recieve", "Server : " + username + " has entered the chat.");
socket.emit("join", room);
}
})
socket.on("send", function(message){
io.in(rooms[socket.id]).emit("recieve", usernames[socket.id] +" : " + message);
})
socket.on("recieve", function(message){
socket.emit("recieve", message);
})
})