コード例 #1
0
 public ServerState()
 {
     if (currentInstance == null)
     {
         currentInstance = this;
     }
     else
     {
         throw new Exception("only one instance of ServerState is allowed");
     }
     flatList = new List<IEntity>();
     playerInfo= new Dictionary<int, PlayerInfo>();
     _server = new GameServer();
     _server.OnClientConnect = new ONet.GameServer.Callback(ClientConnect);
     _server.OnClientDisconnect = new ONet.GameServer.Callback(ClientDisconnect);
     _server.OnClientMessage = new ONet.GameServer.Callback(Message);
     _server.OnError = new ONet.GameServer.ErrorCallback(ErrorMessage);
     _infoStack = new MessageStack<string>(10);
     _errorStack = new MessageStack<string>(10);
     float offset = 150.0f;
     createdEntities.AddRange(BuildingChunk.CreateBuilding(new Vector2(512.0f, 600.0f)));
     createdEntities.AddRange(BuildingChunk.CreateBuilding(new Vector2(512.0f + offset, 600.0f)));
     createdEntities.AddRange(BuildingChunk.CreateBuilding(new Vector2(512.0f + 2 * offset, 600.0f)));
     createdEntities.AddRange(BuildingChunk.CreateBuilding(new Vector2(512.0f - offset, 600.0f)));
     createdEntities.AddRange(BuildingChunk.CreateBuilding(new Vector2(512.0f - 2 * offset, 600.0f)));
 }
コード例 #2
0
ファイル: GameServer.cs プロジェクト: slicedpan/ONet
 public GameServer(int port = 8024)
 {
     if (currentInstance == null)
     {
         currentInstance = this;
     }
     else
     {
         throw new Exception("only one instance of GameServer is allowed!");
     }
     portNumber = port;
 }
コード例 #3
0
ファイル: Connection.cs プロジェクト: slicedpan/ONet
 public Connection(GameServer server, Socket socket, int number, GameServer.Callback disconnect, GameServer.Callback message, GameServer.ErrorCallback error)
 {
     _socket = socket;
     _server = server;
     _error = error;
     _message = message;
     _disconnect = disconnect;
     idNumber = number;
     buffer = new byte[8192];
     try
     {
         _socket.BeginReceive(buffer, 0, 8192, SocketFlags.None, new AsyncCallback(ReceiveData), _socket);
         _socket.Send(GameMessage.initialisationMessage(number));
     }
     catch (Exception se)
     {
         reportError(se.Message);
     }
 }
コード例 #4
0
ファイル: GameServer.cs プロジェクト: slicedpan/ONet
 public void Dispose()
 {
     currentInstance = null;
     socket.Dispose();
 }