Beispiel #1
0
        internal static void SpawnPlayer(int client_id)
        {
            int spawnIndex = 0;

            lock (my_lock)
            {
                bool isSpawned = false;
                while (!isSpawned)
                {
                    for (int i = 0; i < spawnPoints.Count; i++)
                    {
                        if (map[spawnPoints[i].Key, spawnPoints[i].Value] < 0)
                        {
                            map[spawnPoints[i].Key, spawnPoints[i].Value] = client_id;
                            isSpawned  = true;
                            spawnIndex = i;
                            break;
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
            SwayTCP.SendSpawnPoint(client_id, spawnIndex);
            SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
            {
                SwayStation.station.UpdateLog("Spawned player: " + client_id + " to spawn point: " + spawnIndex + "\n");
            });
        }
 private static void Packet_LeftGame(long index, byte[] data)
 {
     SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
     {
         SwayStation.station.ClientLeftGame((int)index);
     });
     SwayTCP.SendPlayerRemoval(index);
 }
 internal void GrantClientManagingPrivilages(int index)
 {
     SwayTCP.Clients[index]._player._role = Player_role.manager;
     UpdateLog("Privilage granted to " + SwayTCP.Clients[index]._player._username + " to manage game.\n");
     SwayTCP.SendManagementPrivilage(index);
     UpdateClientList();
     UpdateNeedle();
 }
        private static void Packet_CLogout(long index, byte[] data)
        {
            SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
            {
                SwayStation.station.UpdateLog(SwayTCP.Clients[index]._player._username + " logged out.\n");
                SwayStation.station.DeleteClientPairing((int)index);
            });

            SwayTCP.SendLogoutSuccess(index);
        }
        private static void Packet_CManage(long index, byte[] data)
        {
            SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
            {
                SwayStation.station.UpdateLog(SwayTCP.Clients[index]._player._username + " has requested game privilages.\n");
                SwayStation.station.AddClientManagingWaitingList((int)index);
            });

            SwayTCP.SendManagingRequestRecieved(index);
        }
 static void SetupServer()
 {
     for (int i = 0; i < Constants.MAX_PLAYERS; i++)
     {
         SwayTCP.Clients[i]  = new Client();
         Types.TempPlayer[i] = new Types.TempPlayerRec();
     }
     ServerHandleData.InitPackets();
     SwayTCP.InitializeNetwork();
 }
        private static void Packet_CShoot(long index, byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);
            buffer.ReadLong();
            float direction = buffer.ReadFloat();

            //handle logic
            SwayTCP.SendRealtimeDirectionToAll(index, direction);
        }
Beispiel #8
0
 private static void WaitForBlockVacancy(long index, int x, int y)
 {
     while (map[x, y] > -1)
     {
         Console.WriteLine("waiting for free block at: " + map[x, y]);
         Thread.Sleep(500);
     }
     //send unblock to tile x,y
     SwayTCP.Clients[index]._player._blockages.Remove(new KeyValuePair <int, int>(x, y));
     SwayTCP.SendUnblock(index, x, y);
 }
        private static void Packet_CRealtimePosition(long index, byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);
            buffer.ReadLong();

            float x        = buffer.ReadFloat();
            float y        = buffer.ReadFloat();
            float rotation = buffer.ReadFloat();

            buffer = null;
            SwayTCP.SendRealtimeUpdateToAll((int)index, x, y, rotation);
        }
        private static void Packet_CUnblock(long index, byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);
            buffer.ReadLong();
            long opponentIndex = buffer.ReadLong();

            SwayStation.station.gameLogic.RemoveBlockHash(index, opponentIndex);
            int x = buffer.ReadInteger();
            int y = buffer.ReadInteger();

            SwayTCP.SendUnblock(opponentIndex, x, y);
        }
        private static void Packet_CInput(long index, byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);
            buffer.ReadLong();
            ClientInput input        = (ClientInput)buffer.ReadInteger();
            int         isKeyPressed = buffer.ReadInteger();
            float       x            = buffer.ReadFloat();
            float       y            = buffer.ReadFloat();
            float       rotation     = buffer.ReadFloat();

            //handle logic
            SwayTCP.SendRealtimeInputToAll(index, input, isKeyPressed, x, y, rotation);
            buffer = null;
        }
 private void CloseSocket()
 {
     _player.Clear();
     _socket.Close();
     _socket = null;
     SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
     {
         SwayTCP.ClientCount--;
         SwayStation.station.gameLogic.Remove(SwayTCP.Clients[_index]);
         SwayStation.station.UpdateLog("Connection from ip: " + _ip + " has been terminated!\n");
         SwayStation.station.UpdateClientNumber(SwayTCP.ClientCount);
     });
     if (_player._isGaming)
     {
         SwayTCP.SendPlayerRemoval(_index);
     }
 }
        private static void Packet_CRegister(long index, byte[] data)
        {
            long       packetNum;
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);
            packetNum = buffer.ReadLong();

            string username   = buffer.ReadString();
            string password   = buffer.ReadString();
            string playerName = buffer.ReadString();

            List <string>[] check = SwayStation.station.UpdatePlayerDataBase(username);
            if (check[0].Count > 0)
            {
                string message = "The username is already taken";
                SwayTCP.SendRegisterFail(index, message);
                SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
                {
                    SwayStation.station.UpdateLog("Username taken error: " + username + "\n");
                });
            }
            else
            {
                SwayStation.station.AddPlayer(username, playerName, password, "" + 1000, "" + 100, "no");
                check = SwayStation.station.UpdatePlayerDataBase(username);
                SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
                {
                    SwayStation.station.AddClientPairing((int)index, check[0][0], username);
                });
                string playerData = index + "/" +
                                    check[(int)Sql_playerData.playername][0] + "/" +
                                    check[(int)Sql_playerData.health][0] + "/" +
                                    check[(int)Sql_playerData.ammo][0] + "/" +
                                    check[(int)Sql_playerData.rank][0] + "/" +
                                    check[(int)Sql_playerData.score][0];
                string message = "Registration successful, " + check[3][0];
                SwayTCP.SendRegisterSuccess(index, message, playerData);
            }
            buffer = null;
        }
        private void AllowMovementFunction()
        {
            int    deltaX;
            int    deltaY;
            int    i;
            int    j;
            string blockHash;

            while (true)
            {
                for (int client1 = 0; client1 < GameClients.Count; client1++)
                {
                    for (int client2 = client1 + 1; client2 < GameClients.Count; client2++)
                    {
                        deltaX    = Math.Abs(GameClients[client1]._player.x - GameClients[client2]._player.x);
                        deltaY    = Math.Abs(GameClients[client1]._player.y - GameClients[client2]._player.y);
                        i         = GameClients[client1]._index;
                        j         = GameClients[client2]._index;
                        blockHash = (((i + j) * (i + j + 1) / 2) + j) + "";
                        if (!(deltaX == 0 & deltaY == 0))
                        {
                            if (deltaX < 2)
                            {
                                if (deltaY < 2)
                                {
                                    if (!blockQueue.Contains(blockHash))
                                    {
                                        blockQueue.Add((((i + j) * (i + j + 1) / 2) + j) + "");
                                        SwayTCP.SendBlock(GameClients[client1]._index, GameClients[client2]._index, GameClients[client1]._player.x, GameClients[client1]._player.y, GameClients[client2]._player.x, GameClients[client2]._player.y);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private static void Packet_CLogin(long index, byte[] data)
        {
            long       packetNum;
            ByteBuffer buffer = new ByteBuffer();

            buffer.WriteBytes(data);
            packetNum = buffer.ReadLong();

            string username = buffer.ReadString();
            string password = buffer.ReadString();

            Console.WriteLine("Login Packet recieved: " + username + " " + password);
            List <string>[] check = SwayStation.station.UpdatePlayerDataBase(username);
            if (check[0].Count > 0)
            {
                if (check[(int)Sql_playerData.password][0].Contains(password))
                {
                    if (check[(int)Sql_playerData.isbanned][0].Equals("yes"))
                    {
                        string message = "You cannot log in, " + check[(int)Sql_playerData.username][0] + " is currently banned";
                        SwayTCP.SendBanMessage(index, message);
                        SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
                        {
                            SwayStation.station.UpdateLog(username + " attempted to log in but is banned\n");
                        });
                    }
                    else
                    {
                        //array of random welcome messages here

                        string playerData =
                            index + "/" +
                            check[(int)Sql_playerData.playername][0] + "/" +
                            check[(int)Sql_playerData.health][0] + "/" +
                            check[(int)Sql_playerData.ammo][0] + "/" +
                            check[(int)Sql_playerData.rank][0] + "/" +
                            check[(int)Sql_playerData.score][0];

                        string message = "Welcome to Space Fight, " + check[(int)Sql_playerData.playername][0];
                        SwayTCP.SendLoginSuccess(index, message, playerData);
                        SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
                        {
                            SwayStation.station.AddClientPairing((int)index, check[0][0], check[1][0]);
                            SwayStation.station.UpdateLog(username + " successfully logged in.\n");
                        });
                    }
                }
                else
                {
                    //array of random welcome messages here
                    string message = "Wrong password.";
                    SwayTCP.SendLoginFail(index, message);
                    SwayStation.station.GetInterface().Invoke((MethodInvoker) delegate
                    {
                        SwayStation.station.UpdateLog(username + " entered wrong password.\n");
                    });
                }
            }
            else
            {
                SwayTCP.SendCredentialsFail(index);
            }
            buffer = null;
        }
 public void SendToEveryone()
 {
     UpdateLog("Sending Message to Everyone: \"" + serverInterface.GetTypedMessage() + "\"\n");
     SwayTCP.SendMessageToAll(serverInterface.GetTypedMessage());
 }
 public void SendToSelectedClients()
 {
     UpdateLog("Sending Message to Selected: \"" + serverInterface.GetTypedMessage() + "\"\n");
     SwayTCP.SendMessageToSelected(serverInterface.GetTypedMessage());
 }