Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Last active December 23, 2015 03:09
Show Gist options
  • Save volgar1x/6571326 to your computer and use it in GitHub Desktop.
Save volgar1x/6571326 to your computer and use it in GitHub Desktop.
trait Context // todo
trait DofusMessage // todo
object DofusProtocol extends DelimitedTextProtocol("\u0000", "\n\u0000") {
def encode(o: Any): Any = o match {
case msg: DofusMessage => super.encode(msg.serialize())
case msg: String => super.encode(msg)
}
def decode(o: Any): Any = super.decode(o) match {
case input: Traversable[String] => input.map(x => messages(x.subtring(0, 2)).map(y => y(input.substring(2))))
}
}
trait NetworkHandler {
type Receive = PartialFunction[(Session, DofusMessage), Unit]
def handler(ctx: Context): Receive
}
class NetworkService(config: Config) {
val ctx = newContext
val service = TcpService(config.getInt("photon.network.port"), DofusProtocol) {
case Connect(session) =>
session ! HelloGame
case Disconnect(session) =>
save(session.account)
case Message(session, msg: DofusMessage) =>
handler(session, msg)
}
val handler = LoginHandler.handler(ctx)
orElse OtherHandler.handler(ctx)
}
object LoginHandler extends NetworkHandler {
def handler(ctx: Context) = {
case (session, msg@AuthReq) =>
session ! AuthResp(success = false)
}
}
object OtherHandler extends NetworkHandler {
def handler(ctx: Context) = {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment