-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'debug-messages' of https://github.com/Vexatos/OpenCompu…
…ters into master-MC1.7.10
- Loading branch information
Showing
7 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
src/main/scala/li/cil/oc/server/command/SendDebugMessageCommand.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package li.cil.oc.server.command | ||
|
||
import li.cil.oc.api.Network | ||
import li.cil.oc.common.command.SimpleCommand | ||
import li.cil.oc.server.network.DebugNetwork | ||
import net.minecraft.command.ICommandSender | ||
import net.minecraft.command.WrongUsageException | ||
|
||
object SendDebugMessageCommand extends SimpleCommand("oc_sendDebugMessage") { | ||
aliases += "oc_sdbg" | ||
|
||
override def getCommandUsage(sender: ICommandSender): String = name + "<destinationAddress> [message...]" | ||
|
||
override def processCommand(sender: ICommandSender, args: Array[String]): Unit = { | ||
if (args == null || args.length == 0) { | ||
throw new WrongUsageException("no destination address specified.") | ||
} | ||
val destination = args(0) | ||
DebugNetwork.getEndpoint(destination).foreach { endpoint => | ||
val packet = Network.newPacket(sender.getCommandSenderName, destination, 0, args.drop(1).toList.toArray[AnyRef]) | ||
endpoint.receivePacket(packet) | ||
} | ||
} | ||
|
||
override def getRequiredPermissionLevel = 2 | ||
} |
This file contains 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
25 changes: 25 additions & 0 deletions
25
src/main/scala/li/cil/oc/server/network/DebugNetwork.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package li.cil.oc.server.network | ||
|
||
import li.cil.oc.api.network.Packet | ||
|
||
import scala.collection.mutable | ||
|
||
object DebugNetwork { | ||
val cards = mutable.WeakHashMap.empty[DebugNode, Unit] | ||
|
||
def add(card: DebugNode) { | ||
cards.put(card, Unit) | ||
} | ||
|
||
def remove(card: DebugNode) { | ||
cards.remove(card) | ||
} | ||
|
||
def getEndpoint(tunnel: String) = cards.keys.find(_.address == tunnel) | ||
|
||
trait DebugNode { | ||
def address: String | ||
|
||
def receivePacket(packet: Packet): Unit | ||
} | ||
} |