Skip to content

Commit

Permalink
Real IP module ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyyf committed Feb 24, 2015
1 parent 37dfd5d commit 60dc282
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
*.log

# Generated plugin list.
minegate/plugin.go
build/plugin.go
4 changes: 2 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

code_template = \
"""
package minegate
package main
import (
{import_packages}
Expand Down Expand Up @@ -65,7 +65,7 @@
print 'No plugins added.'
sys.exit(1)
if packages:
with open('minegate/plugin.go', 'w') as f:
with open('build/plugin.go', 'w') as f:
code_data = code_template.format(
import_packages='\n'.join(
map(lambda s: '\t_ "%s"' %
Expand Down
9 changes: 3 additions & 6 deletions plugins/realip/realip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ func init() {
minegate.OnLoginRequest(HandleLogin, 0)
}

func ToUUID(h []byte) (uuid string) {
if len(h) != 16 {
return ""
}
func ToUUID(h [16]byte) (uuid string) {
h[6] &= 0x0F
h[6] |= 0x30
h[8] &= 0x3F
Expand Down Expand Up @@ -44,15 +41,15 @@ func HandleLogin(lre *minegate.LoginRequestEvent) {
log.Infof("Patching for bungeecord.")
uname := lre.LoginPacket.Name
remoteip := lre.GetRemoteIP()
h := md5.New()
prefix := "OfflinePlayer:"
buff := bytes.NewBuffer(make([]byte, 0, len(prefix)+len(uname)+4))
buff.WriteString(prefix)
buff.WriteString(uname)
// Data is the faked uuid, for offline only.
// Online mode is not available, since online mode introduces protocol encryption.
// For online mode, please use bungeecord!
data := ToUUID(h.Sum(buff.Bytes()))
data := ToUUID(md5.Sum(buff.Bytes()))
log.Debugf("UUID: %s", data)
lre.InitPacket.ServerAddr += "\x00" + remoteip + "\x00" + data
}
return
Expand Down

0 comments on commit 60dc282

Please sign in to comment.