Beispiel #1
0
 private void OnGUI()
 {
     if (side == Side.None)
     {
         if (GUI.Button(new Rect(10, 10, 200, 30), "Start Server"))
         {
             side = Side.Server;
             ServerSocketScript sss = gameObject.AddComponent <ServerSocketScript>();
             sss.Run();
         }
         if (GUI.Button(new Rect(10, 50, 200, 30), "Start Client"))
         {
             side = Side.Client;
             ClientSocketScript css = gameObject.AddComponent <ClientSocketScript>();
             css.Run();
         }
     }
     if (side == Side.Server)
     {
         OnServerGUI();
     }
 }
Beispiel #2
0
    private void OnServerGUI()
    {
        int ScreenW            = Screen.width;
        int ScreenH            = Screen.height;
        ServerSocketScript sss = gameObject.GetComponent <ServerSocketScript>();

        if (GUI.Button(new Rect(ScreenW - 210, 10, 200, 30), "Button"))
        {
        }
        if (GUI.Button(new Rect(ScreenW - 210, 50, 200, 30), "Button"))
        {
        }
        if (GUI.Button(new Rect(ScreenW - 210, 90, 200, 30), "Button"))
        {
        }
        if (GUI.Button(new Rect(ScreenW - 210, 130, 200, 30), "Button"))
        {
        }

        GUIStyle style = GUI.skin.box;

        style.alignment  = TextAnchor.UpperLeft;
        style.fixedWidth = ScreenW - 245;
        style.wordWrap   = true;

        float h     = 0;
        int   count = sss.logServer.Count;

        GUIContent[] msgContent = new GUIContent[count];
        for (int i = 0; i < count; i++)
        {
            msgContent[i] = new GUIContent(sss.logServer[i]);
            h            += style.CalcHeight(msgContent[i], ScreenW - 245);
        }


        scrollPosition = GUI.BeginScrollView(new Rect(10, 10, ScreenW - 230, ScreenH - 55), scrollPosition, new Rect(0, 0, ScreenW - 245, (int)h), false, true);
        h = 0;
        for (int i = 0; i < count; i++)
        {
            float he = style.CalcHeight(msgContent[i], ScreenW - 245);
            GUI.Label(new Rect(0, h, ScreenW - 245, (int)he), msgContent[i], style);
            h += he;
        }
        GUI.EndScrollView();

        textCMD = GUI.TextField(new Rect(10, ScreenH - 40, ScreenW - 340, 30), textCMD);

        if (GUI.Button(new Rect(ScreenW - 320, ScreenH - 40, 100, 30), "Send") || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
        {
            if (textCMD.Length > 0)
            {
                string[] args = textCMD.Split(' ');
                if (args.Length > 0)
                {
                    //COMMAND: help
                    if (args[0].ToLower() == "help")
                    {
                        sss.Log("=============== Liste des commandes ===============");
                        sss.Log("Exemple: nom <obligatoire> (optionnel)");
                        sss.Log("item <templateID> <characterName> (quantity) -> Ajoute un item");
                        sss.Log("delitem <ID/templateID/slotID> <characterName> (type) (quantity) -> Retire un item");
                        sss.Log("\ttype {0 = ID, 1 = templateID, 2 = slotID}; Default = ID");
                    }
                    //COMMAND: item <templateID> <characterName> (quantity)
                    if (args.Length >= 3 && args[0].ToLower() == "item")
                    {
                        string       characterName = args[2].ToLower();
                        int          quantity      = args.Length >= 4 ? Convert.ToInt32(args[3]) : 1;
                        ServerClient sc            = sss.GetServerClientByName(characterName);
                        if (sc != null)
                        {
                            sc.CreateAndSendItem(Convert.ToInt32(args[1]), quantity);
                        }
                        else
                        {
                            sss.Log("FAIL Add Item : " + characterName + " not found");
                        }
                    }
                    //COMMAND: delitem <ID/templateID/slotID> <characterName> (type) (quantity)
                    // type {0 = ID, 1 = templateID, 2 = slotID}; Default = ID
                    if (args.Length >= 3 && args[0].ToLower() == "delitem")
                    {
                        string       characterName = args[2].ToLower();
                        int          type          = args.Length >= 4 ? Convert.ToInt32(args[3]) : 0;
                        int          quantity      = args.Length >= 5 ? Convert.ToInt32(args[4]) : 1;
                        ServerClient sc            = sss.GetServerClientByName(characterName);
                        if (sc != null)
                        {
                            sc.RemoveItem(Convert.ToInt32(args[1]), type, quantity);
                        }
                        else
                        {
                            sss.Log("FAIL Delete Item : " + characterName + " not found");
                        }
                    }
                }
                /* COMMANDE SERVER */
                textCMD = "";
            }
        }
    }
Beispiel #3
0
 public ServerClient(ServerSocketScript ss, Socket socket)
 {
     _ss               = ss;
     _socket           = socket;
     characterSelected = -1;
 }