本文整理匯總了Golang中github.com/minero/minero/server/player.Player.OnlineMode方法的典型用法代碼示例。如果您正苦於以下問題:Golang Player.OnlineMode方法的具體用法?Golang Player.OnlineMode怎麽用?Golang Player.OnlineMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/minero/minero/server/player.Player
的用法示例。
在下文中一共展示了Player.OnlineMode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleFC
// HandleFC handles incoming requests of packet 0xFC: EncryptionKeyResponse
func HandleFC(server *Server, sender *player.Player) {
pkt := new(packet.EncryptionKeyResponse)
pkt.ReadFrom(sender.Conn)
// Decrypt shared secret and token with server's private key.
var secret, token []byte
// var err error
secret, _ = rsa.DecryptPKCS1v15(rand.Reader, server.PrivateKey(), pkt.Secret)
token, _ = rsa.DecryptPKCS1v15(rand.Reader, server.PrivateKey(), pkt.Token)
// Ensure token matches
if !bytes.Equal(token, sender.Token) {
log.Println("Tokens don't match.")
r := &packet.Disconnect{Reason: ReasonPiratedGame}
r.WriteTo(sender.Conn)
return
}
// Ensure player is legit
if !server.CheckUser(sender.Name, secret) {
log.Println("Failed to verify username!")
r := packet.Disconnect{"Failed to verify username!"}
r.WriteTo(sender.Conn)
return
}
// Send empty EncryptionKeyResponse
r := new(packet.EncryptionKeyResponse)
r.WriteTo(sender.Conn)
// Start AES/CFB8 stream encryption
sender.OnlineMode(true, secret)
log.Println("Enabling encryption.")
}