Skip to content

Commit f7b7eaf

Browse files
committed
One port host optimization
1 parent fa9a41e commit f7b7eaf

File tree

9 files changed

+466
-1619
lines changed

9 files changed

+466
-1619
lines changed

coffee/client/module/index.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ init = ()->
5454
})
5555

5656
#Połączenie z serwerem i kontrolki gracza
57-
socket=io.connect "#{al.get("host")}:#{al.get("websocket-port")}"
57+
socket=io.connect "#{document.location.host}"
5858
FPC = new FirstPersonControls {
5959
canvas
6060
camera

coffee/server.coffee

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,21 @@ module.exports=(type)->
44
fs=require "fs"
55
config=JSON.parse fs.readFileSync(__dirname+"/../config.json")
66
http=require "http"
7-
server=http.createServer()
8-
io=require("socket.io")(server)
97
express=require 'express'
8+
app=express()
9+
server=http.createServer(app)
10+
io=require("socket.io")(server)
1011
request = require 'request'
11-
app=express();
1212
mineflayer = require 'mineflayer'
1313
Chunk = require("prismarine-chunk")(config.realServer.version)
1414
vec3=require "vec3"
1515
Convert = require 'ansi-to-html'
1616
convert = new Convert()
1717

18-
# opn("http://#{config.host}:#{config['express-port']}")
19-
2018
#początkowe zmienne
2119
sf={}
22-
port=config["express-port"]
2320
socketInfo={}
2421

25-
getItem=(name,callback)->
26-
mozl=[
27-
"materials"
28-
"armor_recipes"
29-
"basic_recipes"
30-
"block_recipes"
31-
"mobs"
32-
"decoration_recipes"
33-
"dye_recipes"
34-
"firework_recipes"
35-
"food_recipes"
36-
"mechanism_recipes"
37-
"tool_recipes"
38-
"transportation_recipes"
39-
"weapon_recipes"
40-
]
41-
done=0
42-
wysl=false
43-
for i in mozl
44-
options = {
45-
method: 'GET'
46-
url: "https://www.digminecraft.com/#{i}/images/#{name}.png"
47-
encoding: null
48-
}
49-
((options)->
50-
request options, (err, response, body)->
51-
done+=1
52-
if not err and response.statusCode == 200 and wysl is false
53-
wysl=true
54-
callback options.url
55-
56-
else if wysl is false and done is mozl.length
57-
callback "error"
58-
return
59-
)(options)
60-
61-
62-
6322
#Konfiguracja serwera express
6423
if type is "production"
6524
app.use express.static(__dirname + "/dist/")
@@ -68,22 +27,16 @@ module.exports=(type)->
6827
app.use (req, res, next) ->
6928
res.set 'Cache-Control', 'no-store'
7029
next()
71-
app.get "/items/:item",(req,res)->
72-
getItem req.params.item,(resp)->
73-
res.send(resp)
74-
app.get "/websocket/",(req,res)->
75-
res.send String(config["websocket-port"])
76-
app.get "/host/",(req,res)->
77-
res.send String(config["host"])
78-
app.listen port
79-
server.listen config["websocket-port"]
30+
server.listen config["port"],()->
31+
console.log "Server is running on \x1b[34mhttp://localhost:#{config["port"]}\x1b[0m"
32+
# opn("http://#{config.host}:#{config['express-port']}")
8033

8134
#websocket
8235
io.sockets.on "connection", (socket)->
8336
socketInfo[socket.id]={}
8437
bot=socketInfo[socket.id]
8538
socket.on "initClient",(data)->
86-
console.log "[+] "+data.nick
39+
console.log "[\x1b[32m+\x1b[0m] "+data.nick
8740

8841
#Dodawanie informacji o graczu do socketInfo
8942
socketInfo[socket.id]=data
@@ -151,7 +104,7 @@ module.exports=(type)->
151104
"disconnect":()->
152105
try
153106
clearInterval socketInfo[socket.id].int
154-
console.log "[-] "+socketInfo[socket.id].nick
107+
console.log "[\x1b[31m-\x1b[0m] "+socketInfo[socket.id].nick
155108
socketInfo[socket.id].bot.end()
156109
delete socketInfo[socket.id]
157110
return

config.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"websocket-port":35565,
3-
"express-port":8080,
4-
"host":"localhost",
2+
"port":8080,
53
"realServer":{
64
"ip":"localhost",
75
"port":25565,

0 commit comments

Comments
 (0)