Last active
December 23, 2015 03:09
-
-
Save volgar1x/6571326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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