22.02.2011, 11:58
(
Последний раз редактировалось Slice; 14.09.2011 в 19:28.
)
Hey,
I recently started messing around with ******'s own language Go - it's awesome.
Anyway, I made an improvement to the current RCON program that should work on Windows, Linux, and Mac!
Unfortunately I don't have time to go on Mac to compile it - I might do that later (or you can just do it yourself).
I'm planning on integrating WebRCON with this, creating a small HTTP server allowing RCON access from anywhere requiring only a browser.
Download: gorcon.zip.
Source (in the provided zip-archive, as well):
I recently started messing around with ******'s own language Go - it's awesome.
Anyway, I made an improvement to the current RCON program that should work on Windows, Linux, and Mac!
Unfortunately I don't have time to go on Mac to compile it - I might do that later (or you can just do it yourself).
I'm planning on integrating WebRCON with this, creating a small HTTP server allowing RCON access from anywhere requiring only a browser.
Download: gorcon.zip.
Source (in the provided zip-archive, as well):
Код:
import( .."fmt" .."os" .."strings" .."net" .."bytes" .."bufio" ) func.main().{ ..//.Start.the.input.reader ..in.:=.bufio.NewReader(os.Stdin); .. ..fmt.Print("GoRCON.by.Slice\n\n") .. ..server.:=."" ..password.:=."" .. ..if.len(os.Args).>=.3.{ ....server.=.os.Args[1] ....password.=.os.Args[2] ..}.else.{ ....if.len(os.Args).<.2.{ ......fmt.Print("Server:.") ...... ......//.Get.the.server.input ......server,._.=.in.ReadString('\n') ...... ......//.Get.rid.of.the.trailing.newline ......server.=.strings.TrimRight(server,."\r\n") ....}.else.{ ......server.=.os.Args[1] ....} .... ....if.len(os.Args).<.3.{ ......fmt.Print("Password:.") ...... ......//.Get.the.password.input ......password,._.=.in.ReadString('\n') ...... ......//.Get.rid.of.the.trailing.newline ......password.=.strings.TrimRight(password,."\r\n") ....} .... ....fmt.Println() ..} .. ..//.If.no.port.is.specified,.use.the.default.one ..if.strings.Index(server,.":").==.-1.{ ....server.+=.":7777" ..} .. ..addr,.err.:=.net.ResolveUDPAddr(server) .. ..if.err.!=.nil.{ ......fmt.Println("Error:.Invalid.host/IP.") ...... ......return ..} .. ..//.Connect ..sock,.err.:=.net.DialUDP("udp4",.nil,.addr) .. ..//.Make.sure.we're.good.to.go ..if.err.!=.nil.{ ....fmt.Println("Failed.to.connect,.error:",.os.Error(err)) .... ....return ..} .. ..//.Start.reading.on.a.new.thread ..go.func().{ ....//.Allocate.for.reading ....bytesread.:=.make([]byte,.1024) .... ....for.{ ......//.Read.from.the.socket ......n,.err.:=.sock.Read(bytesread) ...... ......//.Output.an.error.or.the.bytes.read ......if.err.!=.nil.{ ........fmt.Println("Error:",.err) ......}.else.{ ........for.i.:=.12;.i.<.n;.i++.{ ..........if.bytesread[i].!=.0.{ ............fmt.Printf("%c",.bytesread[i]) ..........} ........} ........ ........fmt.Println() ......} ....} ..}() .. ..//.Store.the.length.of.the.password ..pwdLen.:=.len(password) .. ..//.Create.the.funcion.that.sends.commands ..sendCommand.:=.func(command.string).{ ....//.Messages.start.with."SAMP" ....writebuf.:=.bytes.NewBuffer([]byte("SAMP")) .... ....//.Store.the.length.of.command ....cmdLen.:=.len(command) .... ....//.No.need.to.send.an.empty.command ....if.cmdLen.<.1.{ ......return ....} .... ....//.Write.the.IP ....writebuf.Write([]byte{addr.IP[12],.addr.IP[13],.addr.IP[14],.addr.IP[15]}) .... ....//.Write.the.port ....writebuf.Write([]byte{byte((addr.Port.>>.8).&.0xFF),.byte(addr.Port.&.0xFF)}) .... ....//.x.for.RCON ....writebuf.Write([]byte{'x'}) .... ....//.Length.of.the.password,.followed.by.the.password. ....writebuf.Write([]byte{byte(pwdLen.&.0xFF),.byte((pwdLen.>>.8).&.0xFF)}) ....writebuf.WriteString(password) .... ....//.Length.of.the.command,.followed.by.the.command. ....writebuf.Write([]byte{byte(cmdLen.&.0xFF),.byte((cmdLen.>>.8).&.0xFF)}) ....writebuf.WriteString(command) .... ....//.Send.it ....sock.Write(writebuf.Bytes()) ..} .. ..sendCommand("echo.GoRCON.connected.\n") .. ..for.{ ....//.Let's.wait.for.console.input ....command,._.:=.in.ReadString('\n') .... ....//.Get.rid.of.the.trailing.newline ....command.=.strings.TrimRight(command,."\r\n") .... ....sendCommand(command) ..} .. ..sock.Close() }