Skip to content

Commit

Permalink
login/logout
Browse files Browse the repository at this point in the history
  • Loading branch information
napthats committed Mar 13, 2012
0 parents commit 61c1c3a
Show file tree
Hide file tree
Showing 228 changed files with 467 additions and 0 deletions.
Binary file added .cache
Binary file not shown.
9 changes: 9 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="lib" path="/Users/user/Documents/workspace/SPHIDM/bin"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
18 changes: 18 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SPHIDM</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Sat Feb 18 15:26:57 JST 2012
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
Binary file added bin/com/napthats/sphidm/AbsoluteDirection$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/AbsoluteDirection.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/AcceptNewUser$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/AcceptNewUser.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Action$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Action.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Backward$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Backward.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Board$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Board.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Cast$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Cast.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ChSrvNo$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ChSrvNo.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ChSrvOk$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ChSrvOk.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Chat$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Chat.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Check$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Check.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ClientId$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ClientId.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ClientMessage$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ClientMessage.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Close$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Close.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CodeEuc$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CodeEuc.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CodeSjis$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CodeSjis.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CodeUtf$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CodeUtf.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CommandToUser$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/CommandToUser.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Direction.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/DisconnectClient$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/DisconnectClient.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/East$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/East.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/EndLag$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/EndLag.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/EnterWin$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/EnterWin.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Equip$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Equip.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Erase$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Erase.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ExMap$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ExMap.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ExSwitch$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ExSwitch.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Exit$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Exit.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ExitPc$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/ExitPc.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/FloorItem$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/FloorItem.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Forward$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Forward.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Get$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Get.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Guard$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Guard.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Hit$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Hit.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Initial$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Initial.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/LeaveWin$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/LeaveWin.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Left$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Left.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Login$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Login.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/LoginSucceeded$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/LoginSucceeded.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Logout$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Logout.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Look$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Look.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Map$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Map.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/MapIv$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/MapIv.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/MessageToClient$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/MessageToClient.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/MessageToUser$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/MessageToUser.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Move$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Move.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/NoSrv$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/NoSrv.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/NoSuchUser$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/NoSuchUser.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/NormalMessage$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/NormalMessage.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/North$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/North.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Open$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Open.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Opened$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Opened.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Pay$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Pay.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhiCommand$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhiCommand.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhiProtocol.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Phidm$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Phidm.class
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhidmProtocolParser.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhidmServer$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhidmServer.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhircId$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PhircId.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlainMessageToUser$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlainMessageToUser.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlayerCharacter$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlayerCharacter.class
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlayerCharacterData.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlayerCharacterId$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlayerCharacterId.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/PlayerCharacterState$.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Priv$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Priv.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Put$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Put.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Read$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Read.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/RelativeDirection$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/RelativeDirection.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Reserve$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Reserve.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Right$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Right.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/See$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/See.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Sort$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Sort.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/South$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/South.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/SpecialPriv$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/SpecialPriv.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Spells$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Spells.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Status$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Status.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/StatusIv$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/StatusIv.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Title$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Title.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Tmp$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Tmp.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Trans$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Trans.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Turn$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Turn.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Ulist$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Ulist.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Unequip$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Unequip.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Use$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Use.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/User$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/User.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserAlreadyLogined$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserAlreadyLogined.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserManager$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserManager.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserMessage$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserMessage.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserSocketActor$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserSocketActor.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/UserState.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Version$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Version.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/VersionClient$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/VersionClient.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/West$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/West.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Write$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/Write.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/X$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/X.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/_ClientMessage$.class
Binary file not shown.
Binary file added bin/com/napthats/sphidm/_ClientMessage.class
Binary file not shown.
Binary file added bin/test/UserManagerTest.class
Binary file not shown.
12 changes: 12 additions & 0 deletions src/com/napthats/sphidm/Phidm.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.napthats.sphidm

import scala.actors.Actor
import scala.actors.Actor._


object Phidm extends Actor {
def act() {

}
}

97 changes: 97 additions & 0 deletions src/com/napthats/sphidm/PhidmProtocolParser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.napthats.sphidm


sealed abstract class PhiProtocol

case class PhiServerToClientProtocol extends PhiProtocol

case class Close extends PhiServerToClientProtocol
case class Tmp extends PhiServerToClientProtocol

case class PhiClientToServerProtocol extends PhiProtocol

case class NormalMessage(msg: String) extends PhiClientToServerProtocol

//client protocol starting with #
case class PhiClientSpecialProtocol extends PhiClientToServerProtocol
case class Open(id: String) extends PhiClientSpecialProtocol
case class EndLag extends PhiClientSpecialProtocol
case class Reserve(id: String) extends PhiClientSpecialProtocol
case class NoSrv extends PhiClientSpecialProtocol
case class Trans(id: String) extends PhiClientSpecialProtocol
case class ChSrvNo extends PhiClientSpecialProtocol
case class ChSrvOk extends PhiClientSpecialProtocol
case class CodeEuc extends PhiClientSpecialProtocol
case class CodeUtf extends PhiClientSpecialProtocol
case class CodeSjis extends PhiClientSpecialProtocol
case class VersionClient(version: String) extends PhiClientSpecialProtocol
case class LeaveWin extends PhiClientSpecialProtocol
case class EnterWin extends PhiClientSpecialProtocol
case class Map extends PhiClientSpecialProtocol
case class MapIv(iv: Int) extends PhiClientSpecialProtocol
case class Status extends PhiClientSpecialProtocol
case class StatusIv(iv: Int) extends PhiClientSpecialProtocol
case class Ulist extends PhiClientSpecialProtocol
case class SpecialPriv(name: String, message: String) extends PhiClientSpecialProtocol
case class X extends PhiClientSpecialProtocol
case class UnknownSpecialProtocol(msg: String) extends PhiClientSpecialProtocol

//client plaintext command
case class PhiCommand extends PhiClientToServerProtocol
case class Move(d: Direction) extends PhiCommand
case class Turn(d: Direction) extends PhiCommand
case class Read extends PhiCommand
case class Board extends PhiCommand
case class Use extends PhiCommand
case class Erase extends PhiCommand
case class FloorItem extends PhiCommand
case class Guard extends PhiCommand
case class Check extends PhiCommand
case class Look extends PhiCommand
case class Pay(amount: Int) extends PhiCommand
case class Equip extends PhiCommand
case class Spells extends PhiCommand
case class Write extends PhiCommand
case class Sort extends PhiCommand
case class Unequip extends PhiCommand
case class Put extends PhiCommand
//case class Y extends PhiCommand
case class Get extends PhiCommand
case class Hit extends PhiCommand
case class Cast extends PhiCommand
case class Exit extends PhiCommand
case class Chat extends PhiCommand
case class Title extends PhiCommand
case class Priv(name: String, message: String) extends PhiCommand
case class Action extends PhiCommand
case class Version extends PhiCommand
case class See extends PhiCommand
case class ExSwitch(key: String, value: String) extends PhiCommand
case class ExMap(key: String, value: String) extends PhiCommand

sealed abstract class Direction
sealed abstract case class RelativeDirection extends Direction
case class Forward extends RelativeDirection
case class Backward extends RelativeDirection
case class Right extends RelativeDirection
case class Left extends RelativeDirection
sealed abstract case class AbsoluteDirection extends Direction
case class North extends AbsoluteDirection
case class South extends AbsoluteDirection
case class East extends AbsoluteDirection
case class West extends AbsoluteDirection


object PhidmProtocolParser {
def protocolToCommand(msg:String): PhiProtocol = {
val (protocolType, remainingString) = if(msg.indexOf(' ') >= 0) msg.splitAt(msg.indexOf(' ')) else msg.splitAt(msg.length)
protocolType match {
case "open" =>
Open(remainingString.drop(1))
case "exit" =>
Exit()
case _ =>
NormalMessage(msg)
}
}
}
19 changes: 19 additions & 0 deletions src/com/napthats/sphidm/PhidmServer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.napthats.sphidm

import _root_.java.net.ServerSocket


object PhidmServer {
val PORT = 20017
Phidm.start()
UserManager.start()
PlayerCharacterManager.start()

def main(args: Array[String]) {
val serverSocket = new ServerSocket(PORT)
while(true) {
val clientSocket = serverSocket accept()
UserManager ! AcceptNewUser(clientSocket)
}
}
}
29 changes: 29 additions & 0 deletions src/com/napthats/sphidm/PlayerCharacter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.napthats.sphidm

import scala.actors.Actor
import scala.actors.Actor._

class PlayerCharacter(pcData: PlayerCharacterData, myPcId: PlayerCharacterId) extends Actor {

def act() {
loop {
react {
case UserMessage(_, _, Exit()) =>
PlayerCharacterManager ! CommandToUser(myPcId, Close())

case UserMessage(_, _, msg) =>
PlayerCharacterManager ! PlainMessageToUser(myPcId, "Your message: " + msg)

case LogoutPlayerCharacter(_) =>
exit()

case x =>
error("Unknown message to PlayerCharacter: " + x.toString())
}
}
}
}

object PlayerCharacter {
def apply(pcData: PlayerCharacterData, pcId: PlayerCharacterId) = new PlayerCharacter(pcData, pcId)
}
86 changes: 86 additions & 0 deletions src/com/napthats/sphidm/PlayerCharacterManager.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.napthats.sphidm

import scala.actors.Actor
import scala.actors.Actor._


abstract case class MessageToUser(pcId: PlayerCharacterId)
case class PlainMessageToUser(_pcId: PlayerCharacterId, msg: String) extends MessageToUser(_pcId)
case class CommandToUser(_pcId: PlayerCharacterId, protocol: PhiServerToClientProtocol) extends MessageToUser(_pcId)

case class PhircId(id: String)
case class PlayerCharacterId(pcId: Int)

case class UserMessage(clientId: ClientId, pcId: PlayerCharacterId, protocolMessage: PhiProtocol)

case class PlayerCharacterStatus(hp: Int, mhp: Int, mp: Int, mmp: Int, karma: Int, money: Int, flevel: Int, wlevel: Int, mlevel: Int, clevel: Int, exp: Int, x: Int, y: Int, dir: Int)

abstract case class PlayerCharacterState
case class Logout extends PlayerCharacterState
case class Login(pcId: PlayerCharacterId) extends PlayerCharacterState
case class PlayerCharacterData(phircIdString: String, name: String, pcStatus: PlayerCharacterStatus)

case class LoginPlayerCharacter(clientId: ClientId, phircId: PhircId)
case class LogoutPlayerCharacter(pcId: PlayerCharacterId)

abstract case class LoginPlayerCharacterResult(clientId: ClientId)
case class LoginSucceeded(_clientId: ClientId, pcId: PlayerCharacterId) extends LoginPlayerCharacterResult(_clientId)
case class NoSuchUser(_clientId: ClientId) extends LoginPlayerCharacterResult(_clientId)
case class UserAlreadyLogined(_clientId: ClientId, pcId: PlayerCharacterId) extends LoginPlayerCharacterResult(_clientId)


object PlayerCharacterManager extends Actor{
private[this] val playerCharacterDataContainer = scala.collection.mutable.Map[PhircId, PlayerCharacterData]()
private[this] val loginedPlayerCharacterContainer = scala.collection.mutable.Map[PlayerCharacterId, PlayerCharacter]()
private[this] val playerCharacterStateContainer = scala.collection.mutable.Map[PhircId, PlayerCharacterState]()
private[this] val pcId2phircId = scala.collection.mutable.Map[PlayerCharacterId, PhircId]()
private[this] var nextPlayerCharacterIdNum = 0

playerCharacterDataContainer(PhircId("test")) = PlayerCharacterData("test", "test chara", PlayerCharacterStatus(1000,2000,500,800,10,1000,1000,1000,1000,1000,100,0,0,0))
playerCharacterStateContainer(PhircId("test")) = Logout()

def act() {
loop {
react {
case x @ MessageToUser(_) =>
UserManager ! x

case LoginPlayerCharacter(clientId, phircId) =>
playerCharacterStateContainer.get(phircId) match {
case Some(Login(pcId)) =>
UserManager ! UserAlreadyLogined(clientId, pcId)
case Some(Logout()) =>
val newPcId = makeNewPlayerCharacter(playerCharacterDataContainer(phircId))
playerCharacterStateContainer(phircId) = Login(newPcId)
pcId2phircId(newPcId) = phircId
UserManager ! LoginSucceeded(clientId, newPcId)
case None =>
UserManager ! NoSuchUser(clientId)
}

case x @ LogoutPlayerCharacter(pcId) =>
val phircId = pcId2phircId(pcId)
pcId2phircId.remove(pcId)
playerCharacterStateContainer(phircId) = Logout()
val pc = loginedPlayerCharacterContainer(pcId)
loginedPlayerCharacterContainer.remove(pcId)
pc ! x

case UserMessage(clientId, pcId, msg) =>
loginedPlayerCharacterContainer(pcId) ! UserMessage(clientId, pcId, msg)

case x =>
error("Unknown message to PlayerCharacterManager: " + x.toString())
}
}
}

private[this] def makeNewPlayerCharacter(pcData: PlayerCharacterData): PlayerCharacterId = {
val currentPlayerCharacterId = PlayerCharacterId(nextPlayerCharacterIdNum)
val pc = PlayerCharacter(pcData, currentPlayerCharacterId)
pc.start()
nextPlayerCharacterIdNum += 1
loginedPlayerCharacterContainer(currentPlayerCharacterId) = pc
currentPlayerCharacterId
}
}
99 changes: 99 additions & 0 deletions src/com/napthats/sphidm/UserManager.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.napthats.sphidm

import scala.actors.Actor
import scala.actors.Actor._
import java.net.Socket


case class AcceptNewUser(clientSocket: Socket)
case class ClientId(id: Int)

sealed abstract class UserState
case class Initial extends UserState
case class Opened(pcId: PlayerCharacterId) extends UserState

private case class User(myClientId: ClientId, mySocketActor: UserSocketActor, myState: UserState)

case class ExitPc(pcId: PlayerCharacterId)

object UserManager extends Actor {
private[this] val userContainer = scala.collection.mutable.Map[ClientId, User]()
private[this] val pcId2ClientId = scala.collection.mutable.Map[PlayerCharacterId, ClientId]()
private[this] var nextClientIdNum = 0

def act() {
loop {
react {
//from PlayerCharacterManager
case x @ MessageToUser(pcId) =>
val User(_, socketActor, _) = userContainer(pcId2ClientId(pcId))
x match {
case PlainMessageToUser(_, msg) =>
socketActor ! MessageToClient(msg)
case CommandToUser(_, command) =>
command match {
case Close() =>
val clientId = pcId2ClientId(pcId)
socketActor ! DisconnectClient()
userContainer.remove(clientId)
pcId2ClientId.remove(pcId)
PlayerCharacterManager ! LogoutPlayerCharacter(pcId)
}
}

case AcceptNewUser(clientSocket) =>
val newClientId = getNextClientId
val userSocketActor = UserSocketActor(clientSocket, newClientId, this)
userSocketActor.start()
userContainer(newClientId) = User(newClientId, userSocketActor, Initial())

case x @ LoginPlayerCharacterResult(clientId) =>
val User(_, socketActor, _) = userContainer(clientId)
x match {
case LoginSucceeded(_, pcId) =>
userContainer(clientId) match {
case User(_, _, Initial()) =>
userContainer(clientId) = User(clientId, socketActor, Opened(pcId))
pcId2ClientId(pcId) = clientId
case User(_, _, Opened(_)) =>
error("Assertion error: User tried to login already logined.")
}
case NoSuchUser(_) =>
socketActor ! MessageToClient("No such user.")
socketActor ! DisconnectClient()
userContainer.remove(clientId)
case UserAlreadyLogined(_, pcId) =>
socketActor ! MessageToClient("User already connected.")
socketActor ! DisconnectClient()
userContainer.remove(clientId)
}

case ClientMessage(msg, clientId) =>
PhidmProtocolParser.protocolToCommand(msg) match {
case Open(id) =>
userContainer(clientId) match {
case User(_, _, Opened(_)) =>
case User(_, mySocketActor, Initial()) =>
PlayerCharacterManager ! LoginPlayerCharacter(clientId, PhircId(id))
}
case x =>
userContainer(clientId) match {
case User(_, _, Opened(pcId)) =>
PlayerCharacterManager ! UserMessage(clientId, pcId, x)
case User(_, _, Initial()) =>
}
}

case x =>
error("Unknown message to UserManager: " + x.toString())
}
}
}

private[this] def getNextClientId: ClientId = {
val currentClientId = nextClientIdNum
nextClientIdNum += 1
ClientId(currentClientId)
}
}

Loading

0 comments on commit 61c1c3a

Please sign in to comment.