Example #1
0
        public static Package ParsePackageString(string packageString)
        {
            Package myPackage = new Package();

            char[] paths = {'<','>'};
            string[] commands = packageString.Split(paths);

            for(int i = 0; i < commands.Length; i++)
            {
                if (commands[i] == "type")
                {
                    myPackage.Type = commands[i + 1];
                }
                if (commands[i] == "to")
                {
                    myPackage.To = commands[i + 1];
                }
                if (commands[i] == "from")
                {
                    myPackage.From = commands[i + 1];
                }
                if (commands[i] == "data")
                {
                    myPackage.Data = commands[i + 1];
                }
            }

            return myPackage;
        }
Example #2
0
 public static string MakePackageString(Package package)
 {
     string PackageString = "";
     PackageString += "<type>" + package.Type + "</type>";
     PackageString += "<to>" + package.To + "</to>";
     PackageString += "<from>" + package.From + "</from>";
     PackageString += "<data>" + package.Data + "</data>";
     return PackageString;
 }
Example #3
0
        /// <summary>
        /// Server task factory.
        /// Depending of what kind of task the client wants the server to do. It return a new ITask object.
        /// Each ITask object dose one or several tasks that the client demands. 
        /// </summary>
        /// <param name="package">Package sent by the client</param>
        /// <param name="clientList">List of connected clients</param>
        /// <returns>ITask object</returns>
        public ITask GetTaskObject(Package package,List<ClientSocket> clientList)
        {
            switch (package.Type)
            {
                case "login":
                    return new LoginTaskObj(package,clientList);
                case "newgame":
                    return new NewGameTaskObj(package, clientList);
                case "gamepattern":
                    return new GamePatternTaskObj(package, clientList);
            }

            return null;
        }
Example #4
0
        private string MakeListOfClients()
        {
            string Clients = "";

            LoginPackage = new Package();
            LoginPackage.Type = "userlist";
            LoginPackage.From = "server";
            LoginPackage.To = "all";

            foreach (ClientSocket cs in ClientList)
            {
                Clients += cs.ClientIp + ";";
            }

            LoginPackage.Data = Clients;

            return PacketParser.MakePackageString(LoginPackage); ;
        }
Example #5
0
 public NewGameTaskObj(Package gamePackage,List<ClientSocket> clientList)
 {
     GamePackage = gamePackage;
     ClientList = clientList;
 }
 public GamePatternTaskObj(Package gamePatternPackage, List<ClientSocket> clientList)
 {
     GamePatternPackage = gamePatternPackage;
     ClientList = clientList;
 }
Example #7
0
 public LoginTaskObj(Package loginPackage,List<ClientSocket> clientList)
 {
     LoginPackage = loginPackage;
     ClientList = clientList;
 }
Example #8
0
 /// <summary>
 /// Creates a new task object for each new task the client sends
 /// to the server. Then run the DoTask method
 /// </summary>
 /// <param name="package">Package sent by the client</param>
 private void HandleClientTask(Package package)
 {
     TaskFactory ServerTaskFactory = new TaskFactory();
     ITask ServerTask = ServerTaskFactory.GetTaskObject(package,ClientList);
     ServerTask.DoTask();
 }