-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.go
More file actions
39 lines (31 loc) · 836 Bytes
/
connection.go
File metadata and controls
39 lines (31 loc) · 836 Bytes
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
package main
import "log"
import "net"
// Connection goroutine
func connectionHandler(c net.Conn) {
// TODO:
// Check for ipbans, etc.
defer func() {
c.Close()
log.Printf("Connection from %v closed.\n", c.RemoteAddr())
}()
// Wait for auth packet
packet := make([]byte, 1024)
_, err := c.Read(packet)
if err != nil {
log.Println(err)
return
}
// First 2 bytes represent the packet_id
packet_id := int(packet[0])<<0 | int(packet[1])<<8
switch packet_id {
// Client auth
case PKT_ENTER, PKT_ENTER2:
clientEnter(c, packet)
// Char server auth
case PKT_CHR_ENTER:
charServerEnter(c, packet)
default:
log.Printf("Abnormal end of connection (ip: %s): Unknown packet 0x%x\n", c.RemoteAddr(), packet_id)
}
}