public void UpdatePlantID(string userName, int plantPos, int plantID)
    {
        Debug.Log("loginScript - UpdatePlantID is called");
        scObject data = new scObject("UpdatePlantIDInfo");

        data.addString("account", userName);
        data.addInt("plantPos", plantPos);
        data.addInt("plantID", plantID);
        message mes = new message("UpdatePlantID");

        mes.addSCObject(data);
        SendServerMessage(mes);
    }
Beispiel #2
0
    private message buildMessage()
    {
        message  m           = new message("game");
        scObject information = new scObject("header");

        information.addInt("num_snake", playerList.players.Count);
        m.addSCObject(information);

        for (int i = 0; i < playerList.players.Count; i++)
        {
            m.addSCObject(playerList.players [i].snake.snakeToSCObject());
        }

        //get the scoreboard list
        List <Pair <string, int> > tempboard = new List <Pair <string, int> >();

        foreach (Player p in playerList.players)
        {
            string name  = p.username;
            int    score = p.snake.length();
            tempboard.Add(new Pair <string, int> (name, score));
        }
        tempboard.Sort(SortByScore);
        scoreboard = tempboard;

        return(m);
    }
    public void UpdatePlantExp(string userName, int plantPos, int level, int expName, float expAmount)
    {
        //expName 에는 waterExp, sunExp 등등 중에 하나 들어가야됨, 나중에 이것도 이넘형으로 바꾸기
        //PlantPos가 기본키니깐...필요...
        Debug.Log("*******************loginScript - UpdatePlantExp is success************************");
        Debug.Log("Plant Position = " + plantPos + "      Level is = " + level + "      expName is = " + expName);
        scObject data = new scObject("UpdatePlantExpInfo");

        data.addString("account", userName);
        data.addInt("plantPos", plantPos);
        data.addInt("level", level);
        data.addInt("expName", expName);
        data.addFloat("expAmount", expAmount);
        message mes = new message("UpdatePlantExp");

        mes.addSCObject(data);
        SendServerMessage(mes);
    }
Beispiel #4
0
    private message buildLobbyMessage(bool start, int id)
    {
        message m = new message ("lobby");
        scObject lobby = new scObject ("lobby");
        lobby.addInt ("num_player", playerList.players.Count);

        lobby.addBool ("start", start);
        lobby.addInt ("start_id", id);

        GameObject.Find ("PlayerList").GetComponent<PlayerList> ().startId = id;

        for (int i = 0; i < playerList.players.Count; i++) {
            lobby.addString (i + "_username", playerList.players [i].username);
        }

        m.addSCObject (lobby);
        return m;
    }
    } // userName이 가지고 있는 itemName

    //이거 지금 사실상 거의 씨앗심을때만 사용하고잇음..
    //나중에 테이블을 추가해야된다면 테이블 이름도 변수로 받아서 생성되게 변경할 수 있다. 테이블명에 userName가 들어간다면 조합해서 사용하면되고
    //아니면 그냥 테이블 이름 직접 써주면되고
    //식물리스트테이블에다가 식물의 이름 위치 해당 식물의 경험치를 넣어주는 함수. 씨앗심거나 위치 옮길때 사용
    //userName는 아이디, plantName 식물이름, itemName는 올릴경험치종류(= PlantList테이블의 필드명, WaterEXP, SunEXP, FertilizerEXP, 중 하나)
    //level은 레벨, expAmount는 올려주고싶은 경험치량, posNumber 식물 위치
    //우리 경험치 다 따로 만들기로 했던거 알지? 그래서 이렇게 해놓음...
    //아이템리스트테이블 필드(PlantPos, PlantName, PlantID, Lv, WaterEXP, SunEXP, FertilizerEXP)
    //////////수정 필수,,,, 더이상 update의 의미가없다
    public void UpdatePlantListTable(string userName, string plantName, int plantID, string itemName, int posNumber, int level,
                                     float expAmount, bool isSeedItem)
    {
        Debug.Log("loginScript - UpdatePlantListTable is called");
        scObject data = new scObject("UpdatePlantListTableInfo");

        data.addString("account", userName);
        data.addString("plantName", plantName);
        data.addString("itemName", itemName);
        data.addInt("plantID", plantID);
        data.addInt("posNumber", posNumber);
        data.addInt("level", level);
        data.addFloat("expAmount", expAmount);
        data.addBool("isSeedItem", isSeedItem);
        message mes = new message("UpdatePlantListTable");

        mes.addSCObject(data);
        SendServerMessage(mes);
    }
Beispiel #6
0
    //spawn the food
    void Spawn()
    {
        //x position between left & right border
        int x = (int)Random.Range(-30, 30);

        //y position between top & bottom border
        int y = (int)Random.Range(-13, 13);

        //instantiate the food
        int type = (int)Random.Range(1, 6);

        if (type == 1 || type == 2 || type == 3)
        {
            Instantiate(apple, new Vector2(x, y),
                        Quaternion.identity);
        }
        else if (type == 4)
        {
            Instantiate(onion, new Vector2(x, y),
                        Quaternion.identity);
        }
        else if (type == 5)
        {
            Instantiate(rat, new Vector2(x, y),
                        Quaternion.identity);
        }

        message  m        = new message("food");
        scObject foodInfo = new scObject("foodInfo");

        foodInfo.addInt("type", type);
        foodInfo.addInt("xPos", x);
        foodInfo.addInt("yPos", y);
        m.addSCObject(foodInfo);

        List <Connection> clients = Server.Instance.getClients();

        for (int i = 0; i < clients.Count; i++)
        {
            Server.Instance.sendClientMessage(clients[i], m);
        }
    }
    public void UseItem(string userName, string itemName, int itemNum) // 아이템을 사용하기 위해 서버로 계정과 사용할 아이템 정보 전달
    {
        scObject data = new scObject("useiteminfo");

        data.addString("account", userName);
        data.addString("itemName", itemName);
        data.addInt("itemNum", itemNum);
        message mes = new message("UseItem");

        mes.addSCObject(data);
        SendServerMessage(mes);
        Debug.Log("loginScene - UseItem Success.");
    } // userName이 itemName 사용
Beispiel #8
0
        public void Disconnect()
        {
            output.outToScreen("모든 클라이언트와 연결 끊기");
            int      i         = 0;
            message  Disconnet = new message("DisconnectResponse");
            scObject data      = new scObject("data");

            data.addInt("disconnect", 1);
            Disconnet.addSCObject(data);
            for (i = 0; i < clientSockets.Count(); i++)
            {
                sendClientMessage(clientSockets[i], Disconnet);
            }
        }
Beispiel #9
0
    public scObject snakeToSCObject()
    {
        // Segment for head
        scObject snake = new scObject("snake");

        snake.addString("username", Client.Instance.username);
        snake.addFloat("xPos", transform.position.x);
        snake.addFloat("yPos", transform.position.y);
        snake.addFloat("zPos", transform.position.z);
        snake.addFloat("xRot", transform.rotation.eulerAngles.x);
        snake.addFloat("yRot", transform.rotation.eulerAngles.y);
        snake.addFloat("zRot", transform.rotation.eulerAngles.z);
        snake.addInt("segments", segments.Count);

        // New object for each segment
        for (int i = 0; i < segments.Count; i++)
        {
            snake.addFloat(i + "_xPos", segments [i].transform.position.x);
            snake.addFloat(i + "_yPos", segments [i].transform.position.y);
            snake.addFloat(i + "_zPos", segments [i].transform.position.z);
        }

        return(snake);
    }
Beispiel #10
0
        public void handleClientData(Socket cSock, message incObject)
        {
            Stopwatch Sw = new Stopwatch();

            switch (incObject.messageText)
            {
            case "home":
                message home = new message("homeResponse");
                cSock.Shutdown(SocketShutdown.Receive);
                if (true)
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    home.addSCObject(data);
                    sendClientMessage(cSock, home);
                }
                break;

            case "close":
                message close = new message("closeResponse");
                cSock.Shutdown(SocketShutdown.Receive);
                if (true)
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    close.addSCObject(data);
                    sendClientMessage(cSock, close);
                }
                break;

            case "login":
                //output.outToScreen("serverTCP - login 정상 실행.");
                message login = new message("loginResponse");
                if (playerTools.checkLogin(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("password")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    login.addSCObject(data);
                    output.outToScreen("loginScript - loginResponse에 True 값 전달.");
                }

                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    login.addSCObject(data);
                    output.outToScreen("loginScript - loginResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, login);
                break;

            case "register":
                //output.outToScreen("serverTCP - register 정상 실행.");
                message register = new message("registerResponse");
                if (playerTools.createregister(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("password")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    register.addSCObject(data);
                    output.outToScreen("loginScript - registerResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    register.addSCObject(data);
                    output.outToScreen("loginScript - registerResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, register);
                break;

            case "url":
                //output.outToScreen("serverTCP - url 정상 실행.");
                message url = new message("urlResponse");
                if (playerTools.createurl(incObject.getSCObject(0).getString("url"), incObject.getSCObject(0).getString("account")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    url.addSCObject(data);
                    output.outToScreen("loginScript - urlResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    url.addSCObject(data);
                    output.outToScreen("loginScript - urlResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, url);
                break;

            case "getItem":
                //output.outToScreen("serverTCP - getItem 정상 실행.");
                message getitem = new message("getItemResponse");
                if (playerTools.getItem(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("itemName")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    getitem.addSCObject(data);
                    output.outToScreen("loginScript - getItemResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    getitem.addSCObject(data);
                    output.outToScreen("loginScript - getItemResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, getitem);
                break;

            case "UpdatePlantListTable":
                //output.outToScreen("serverTCP - UpdatePlantListTable 정상 실행.");
                message updatePlantListTableMes = new message("UpdatePlantListTableResponse");
                if (playerTools.UpdatePlantListTable(incObject.getSCObject(0).getString("account"),
                                                     incObject.getSCObject(0).getString("plantName"),
                                                     incObject.getSCObject(0).getInt("plantID"),
                                                     incObject.getSCObject(0).getString("itemName"), incObject.getSCObject(0).getInt("posNumber"),
                                                     incObject.getSCObject(0).getInt("level"), incObject.getSCObject(0).getFloat("expAmount"),
                                                     incObject.getSCObject(0).getBool("isSeedItem")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    updatePlantListTableMes.addSCObject(data);
                    output.outToScreen("loginScript - UpdatePlantListTable에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    updatePlantListTableMes.addSCObject(data);
                    output.outToScreen("loginScript - UpdatePlantListTable에 False 값 전달.");
                }
                sendClientMessage(cSock, updatePlantListTableMes);
                break;

            case "SelectQuery":
                //output.outToScreen("serverTCP - SelectQuery 정상 실행.");
                message selectQueryMes = new message("SelectQueryResponse");
                if (playerTools.SelectQuery(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("columnName"),
                                            incObject.getSCObject(0).getString("tableName")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    data.addInt("plantListTableCount", playerTools.plantPos.Count);
                    for (int i = 0; i <= playerTools.plantPos.Count - 1; i++)
                    {
                        data.addInt("plantPos[" + i + "]", playerTools.plantPos[i]);
                        data.addString("plantName[" + i + "]", playerTools.plantName[i]);
                        data.addInt("plantID[" + i + "]", playerTools.plantID[i]);
                        data.addInt("Lv[" + i + "]", playerTools.Lv[i]);
                        data.addFloat("waterEXP[" + i + "]", playerTools.waterEXP[i]);
                        data.addFloat("sunEXP[" + i + "]", playerTools.sunEXP[i]);
                        data.addFloat("fertilizerEXP[" + i + "]", playerTools.fertilizerEXP[i]);
                    }
                    ////고민중, 걍 노가다임시방편으로 할지 여러 곳에 사용될수잇게 만들지.. 테이블마다 컬럼 개수가 다를 텐데 어떻게 다 가져오지?
                    //위에 써놓음, 다시말하면 2차원배열 만들면됨, 배열 크기는 loginScript에서 넘겨받으면됨,
                    //근데 보통 테이블마다 따로 짠다고하니 별 상관 없을듯함
                    selectQueryMes.addSCObject(data);
                    output.outToScreen("loginScript - SelectQueryResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    selectQueryMes.addSCObject(data);
                    output.outToScreen("loginScript - SelectQueryResponse에 False 값 전달.");
                }
                playerTools.plantPos.Clear();
                playerTools.plantName.Clear();
                playerTools.plantID.Clear();
                playerTools.Lv.Clear();
                playerTools.waterEXP.Clear();
                playerTools.sunEXP.Clear();
                playerTools.fertilizerEXP.Clear();
                sendClientMessage(cSock, selectQueryMes);
                break;

            case "UpdatePlantExp":
                //output.outToScreen("serverTCP - SelectQuery 정상 실행.");
                message UpdatePlantExpMes = new message("UpdatePlantExpResponse");
                if (playerTools.UpdatePlantExp(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getInt("plantPos"),
                                               incObject.getSCObject(0).getInt("level"), incObject.getSCObject(0).getInt("expName"), incObject.getSCObject(0).getFloat("expAmount")))
                {
                    output.outToScreen("SeverTCP - UpdatePlantExp is complete");
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    UpdatePlantExpMes.addSCObject(data);
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    UpdatePlantExpMes.addSCObject(data);
                }
                //sendClientMessage(cSock, UpdatePlantExpMes);
                break;

            case "UpdatePlantID":
                message UpdatePlantIDMes = new message("UpdatePlantIDResponse");
                if (playerTools.UpdatePlantID(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getInt("plantPos"),
                                              incObject.getSCObject(0).getInt("plantID")))
                {
                    output.outToScreen("SeverTCP - UpdatePlantID is complete");
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    UpdatePlantIDMes.addSCObject(data);
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    UpdatePlantIDMes.addSCObject(data);
                }
                //sendClientMessage(cSock, UpdatePlantExpMes);
                break;

            case "ItemCountCheck":
                //output.outToScreen("serverTCP - ItemCountCheck 정상 실행.");
                message itemcountcheck = new message("ItemCountCheckResponse");
                if (playerTools.ItemCountCheck(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("itemName")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);

                    if (playerTools.number == playerTools.wItemNum)
                    {
                        data.addInt("wItemNum", playerTools.wItemNum);
                        itemcountcheck.addSCObject(data);
                        //output.outToScreen("loginScript - ItemCountCheckResponse에 True 값과 wItemNum 값 전달.");
                    }
                    if (playerTools.number2 == playerTools.fItemNum)
                    {
                        data.addInt("fItemNum", playerTools.fItemNum);
                        itemcountcheck.addSCObject(data);
                        //output.outToScreen("loginScript - ItemCountCheckResponse에 True 값과 fItemNum 값 전달.");
                    }
                    if (playerTools.number3 == playerTools.sItemNum)
                    {
                        data.addInt("sItemNum", playerTools.sItemNum);
                        itemcountcheck.addSCObject(data);
                        //output.outToScreen("loginScript - ItemCountCheckResponse에 True 값과 sItemNum 값 전달.");
                    }
                    if (playerTools.number4 == playerTools.nItemNum)
                    {
                        data.addInt("nItemNum", playerTools.nItemNum);
                        itemcountcheck.addSCObject(data);
                        //output.outToScreen("loginScript - ItemCountCheckResponse에 True 값과 nItemNum 값 전달.");
                    }
                    if (playerTools.number5 == playerTools.sfsItemNum)
                    {
                        data.addInt("sfsItemNum", playerTools.sfsItemNum);
                        itemcountcheck.addSCObject(data);
                        //output.outToScreen("loginScript - ItemCountCheckResponse에 True 값과 sfsItemNum 값 전달.");
                    }
                    if (playerTools.number6 == playerTools.csItemNum)
                    {
                        data.addInt("csItemNum", playerTools.csItemNum);
                        itemcountcheck.addSCObject(data);
                        //output.outToScreen("loginScript - ItemCountCheckResponse에 True 값과 csItemNum 값 전달.");
                    }
                    if (playerTools.number7 == playerTools.tsItemNum)
                    {
                        data.addInt("tsItemNum", playerTools.tsItemNum);
                        itemcountcheck.addSCObject(data);
                        //output.outToScreen("loginScript - ItemCountCheckResponse에 True 값과 tsItemNum 값 전달.");
                    }
                    output.outToScreen("loginScript - ItemCountCheckResponse에 True 값 전달");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    itemcountcheck.addSCObject(data);
                    output.outToScreen("loginScript - ItemCountCheckResponse에 False 값 전달.");
                }

                sendClientMessage(cSock, itemcountcheck);
                break;

            case "urlcheck":
                //output.outToScreen("serverTCP - urlcheck 정상 실행.");
                message urlcheck = new message("urlcheckResponse");
                if (playerTools.urlcheck(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("password")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    urlcheck.addSCObject(data);
                    output.outToScreen("loginScript - urlcheckResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    urlcheck.addSCObject(data);
                    output.outToScreen("loginScript - urlcheckResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, urlcheck);
                break;

            case "UseItem":
                //output.outToScreen("serverTCP - UseItem 정상 실행.");
                message useitem = new message("UseItemResponse");
                if (playerTools.UseItem(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("itemName"), incObject.getSCObject(0).getInt("itemNum")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    data.addInt("wItemNum", playerTools.number);
                    data.addInt("fItemNum", playerTools.number2);
                    data.addInt("sItemNum", playerTools.number3);
                    data.addInt("nItemNum", playerTools.number4);
                    data.addInt("sfsItemNum", playerTools.number5);
                    data.addInt("csItemNum", playerTools.number6);
                    data.addInt("tsItemNum", playerTools.number7);
                    useitem.addSCObject(data);
                    output.outToScreen("loginScript - UseItemResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    useitem.addSCObject(data);
                    output.outToScreen("loginScript - UseItemResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, useitem);
                break;

            case "sendtime":
                message sendtime = new message("sendtimeresponse");
                if (playerTools.sendtime(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getFloat("time"), incObject.getSCObject(0).getString("scenename")))
                {
                    output.outToScreen("");
                }
                break;

            case "plusExp":
                //output.outToScreen("serverTCP - plusExp 정상 실행.");
                message plusExp = new message("plusExpResponse");
                if (playerTools.plusExp(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("password")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    plusExp.addSCObject(data);
                    output.outToScreen("loginScript - plusExpResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    plusExp.addSCObject(data);
                    output.outToScreen("loginScript - plusExpResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, plusExp);
                break;

            case "CheckExp":
                //output.outToScreen("serverTCP - CheckExp 정상 실행.");
                message CheckExp = new message("CheckExpResponse");
                if (playerTools.CheckExp(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("password")))
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    data.addInt("Exp", playerTools.Exp);
                    CheckExp.addSCObject(data);
                    output.outToScreen("loginScript - CheckExpResponse에 True 값 전달.");
                }
                else
                {
                    scObject data = new scObject("data");
                    data.addBool("response", false);
                    CheckExp.addSCObject(data);
                    output.outToScreen("loginScript - CheckExpResponse에 False 값 전달.");
                }
                sendClientMessage(cSock, CheckExp);
                break;

            case "getplantname":     //이부분도 수정이 필요하다. 첨에 대전 버튼 누르면 되는데 아니면 안된다.
                message GetPlantNameMessage = new message("GetPlantNameResponse");
                if (true)
                {
                    string name = "";
                    char   sp   = ',';
                    name = playerTools.GetPlantName(incObject.getSCObject(0).getString("account"));
                    string[] spstring = name.Split(sp);
                    scObject data     = new scObject("data");
                    data.addBool("response", true);
                    data.addString("name1", spstring[0]);
                    data.addString("name2", spstring[1]);
                    data.addString("name3", spstring[2]);
                    data.addString("name4", spstring[3]);
                    GetPlantNameMessage.addSCObject(data);
                    sendClientMessage(cSock, GetPlantNameMessage);
                }

                /*else
                 * {
                 *  output.outToScreen("식물 이름 받아오기 실패");
                 *  scObject data = new scObject("data");
                 *  data.addBool("response", false);
                 *  GetPlantNameMessage.addSCObject(data);
                 *  sendClientMessage(cSock, GetPlantNameMessage);
                 * }*/
                break;

            case "transferip":
                message newMessage10 = new message("TransferIPResponse");
                if (clientSockets.Contains(cSock))
                {
                    output.outToScreen("중복 아이피 또는 Socket 입니다. " + incObject.getSCObject(0).getString("battleip") + cSock);
                }
                else
                {
                    clientSockets.Add(cSock);
                }

                if (clientSockets.Count == 2)
                {
                    clientinfos.Add(clientSockets[0], clientSockets[1]);     //KEY VALUE
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    newMessage10.addSCObject(data);
                    sendClientMessage(clientSockets[0], newMessage10);
                    sendClientMessage(clientSockets[1], newMessage10);
                    clientSockets.Clear();
                }
                else
                {
                    scObject data = new scObject("data");
                    output.outToScreen("매칭 인원이 부족합니다.");
                    data.addBool("response", false);
                    sendClientMessage(clientSockets[0], newMessage10);
                }
                break;

            case "addrank":
                message addRank = new message("addRankResponse");
                if (true)
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    data.addInt("rankpoint", playerTools.addrank(incObject.getSCObject(0).getString("account")));
                    addRank.addSCObject(data);
                }
                else
                {
                }
                sendClientMessage(cSock, addRank);
                break;

            case "subtractionrank":
                message subtractionrank = new message("subtractionRankResponse");
                if (true)
                {
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    data.addInt("rankpoint", playerTools.subtractionrank(incObject.getSCObject(0).getString("account")));
                    subtractionrank.addSCObject(data);
                }
                else
                {
                }
                sendClientMessage(cSock, subtractionrank);
                break;

            case "sendplantname":
                if (playerTools.sendplantname(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("plantname")))
                {
                    output.outToScreen("sendplantName");    //이제 로그인 스크립트에 저장된 이름 다시 쏴줘야해
                }
                break;

            case "alldeleteplantname":
                if (playerTools.AllDeletePlantName(incObject.getSCObject(0).getString("account")))
                {
                    output.outToScreen("이름 전부 초기화");
                }
                break;

            case "deleteplantname":
                if (playerTools.DeletePlantName(incObject.getSCObject(0).getString("account"), incObject.getSCObject(0).getString("plantname")))
                {
                    output.outToScreen("이름 1개 완료");
                }
                break;

            case "sendcardmessage":     //왜 안되는지 모르겠음
                message SendCreateMyCard = new message("MyCardResponse");
                message SendCreateAICard = new message("SendCreateAICardResponse");
                if (clientinfos.ContainsKey(cSock) || clientinfos.ContainsValue(cSock))
                {
                    plantname = incObject.getSCObject(0).getString("plantname");
                    scObject data = new scObject("data");
                    data.addBool("response", true);
                    data.addString("plantname", plantname);
                    SendCreateMyCard.addSCObject(data);
                    SendCreateAICard.addSCObject(data);

                    if (clientinfos.ContainsKey(cSock))
                    {
                        clientinfos.TryGetValue(cSock, out value_Value);
                        sendClientMessage(value_Value, SendCreateAICard);
                        sendClientMessage(cSock, SendCreateMyCard);
                    }
                    else if (clientinfos.ContainsValue(cSock))
                    {
                        value_Key = clientinfos.FirstOrDefault(x => x.Value == cSock).Key;
                        sendClientMessage(value_Key, SendCreateAICard);
                        sendClientMessage(cSock, SendCreateMyCard);
                    }
                }
                else
                {
                }
                break;

            case "senddestroyotherobject":     //내 오브젝트 파괴 했다는 메세지 받았을때;
            {
                output.outToScreen("??");
                message  newMessage13 = new message("SendDestroyMyObjectResponse");
                scObject data         = new scObject("data");
                data.addBool("response", true);
                newMessage13.addSCObject(data);

                message  newMessage14 = new message("SendDestroyAiObjectResponse");
                scObject data1        = new scObject("data1");
                data1.addBool("response", true);
                newMessage14.addSCObject(data1);

                if (clientinfos.ContainsKey(cSock))
                {
                    clientinfos.TryGetValue(cSock, out value_Value);
                    sendClientMessage(cSock, newMessage14);
                    sendClientMessage(value_Value, newMessage13);
                }

                else if (clientinfos.ContainsValue(cSock))
                {
                    value_Key = clientinfos.FirstOrDefault(x => x.Value == cSock).Key;
                    sendClientMessage(cSock, newMessage14);
                    sendClientMessage(value_Key, newMessage13);
                }
                output.outToScreen("" + newMessage14);
            }
            break;

            case "senddestroycastle":
            {
                output.outToScreen("???");
                message  newMessage15 = new message("SendDestroyMyCastleResponse");
                scObject data         = new scObject("data");
                data.addBool("response", true);
                newMessage15.addSCObject(data);

                message  newMessage16 = new message("SendDestroyAiCastleResponse");
                scObject data1        = new scObject("data1");
                data1.addBool("response", true);
                newMessage16.addSCObject(data1);

                message  newMessage17 = new message("SendVictoryResponse");
                scObject data2        = new scObject("data2");
                data2.addBool("response", true);
                newMessage17.addSCObject(data2);

                message  newMessage18 = new message("SendLoseResponse");
                scObject data3        = new scObject("data3");
                data3.addBool("response", true);
                newMessage18.addSCObject(data3);

                if (clientinfos.ContainsKey(cSock))
                {
                    clientinfos.TryGetValue(cSock, out value_Value);
                    sendClientMessage(cSock, newMessage16);
                    sendClientMessage(value_Value, newMessage15);
                    sendClientMessage(cSock, newMessage17);
                    sendClientMessage(value_Value, newMessage18);
                }

                else if (clientinfos.ContainsValue(cSock))
                {
                    value_Key = clientinfos.FirstOrDefault(x => x.Value == cSock).Key;
                    sendClientMessage(cSock, newMessage16);
                    sendClientMessage(value_Key, newMessage15);
                    sendClientMessage(cSock, newMessage17);
                    sendClientMessage(value_Key, newMessage18);
                }
                clientinfos.Remove(cSock);
                output.outToScreen("" + newMessage15);
            }
            break;


            default:
                output.outToScreen("The client sent a message: " + incObject.messageText);
                break;
            }
        }
    public void ui_loop()
    {
        float mod = ((Screen.width * 1.0f) / Screen.height)/3;
        GUI.skin = bt;
        if (_modele_game_ref.tick >= (600 * _modele_game_ref.difficulty))
        {
            _modele_game_ref.tick = 0;
            _modele_game_ref.scoreTemp = _modele_game_ref.scoreP1;
            _modele_game_ref.hitTemp = _modele_game_ref.hit;
            _modele_game_ref.successTemp = _modele_game_ref.success;
            _modele_game_ref.chansons.addSCObject(_venyl.destroy());
            _modele_game_ref.isPlaying = false;
            if (_modele_game_ref.manche % 2 != 0)
            {
                instanceMenu = (GameObject)Object.Instantiate(PochMenu);
            }
            else
            {
                scObject dataP1 = _modele_game_ref.scoreData.getSCObject((_modele_game_ref.manche - 2));
                scObject dataP2 = new scObject(_modele_game_ref.manche.ToString());
                if (_modele_game_ref.hit == 0)
                {
                    _modele_game_ref.hit = 1;
                }
                dataP2.addInt("hit", _modele_game_ref.hit);
                dataP2.addInt("succes", _modele_game_ref.success);
                dataP2.addInt("score", _modele_game_ref.scoreP2);
                float scoreP1= ((dataP1.getInt("succes") * 1f) / dataP1.getInt("hit") * (dataP1.getInt("score")));
                float scoreP2= (((dataP2.getInt("succes") * 1f) / dataP2.getInt("hit")) * (dataP2.getInt("score")));
                instanceMeter = (GameObject)Object.Instantiate(meter);
                // afficher lorsque manche est paire???
                if (scoreP2 < scoreP1)
                {
                    lecteur=new player(this, _modele_game_ref.chansons.getSCObject( _modele_game_ref.chansons.getSCObjectCount()-2));
                    instanceMeter.transform.GetChild(0).transform.Rotate(0,0,(((scoreP1-scoreP2)/(scoreP1+scoreP2))*45));
                }
                else
                {
                    lecteur = new player(this, _modele_game_ref.chansons.getSCObject(_modele_game_ref.chansons.getSCObjectCount() - 1));
                    instanceMeter.transform.GetChild(0).transform.Rotate(0, 0, -(((scoreP2 - scoreP1) / (scoreP1 + scoreP2))*45));
                }

                //instanceFen1 = (GameObject)Object.Instantiate(fenetre);
                //instanceFen2 = (GameObject)Object.Instantiate(fenetre);

                instanceBar1 = (GameObject)Object.Instantiate(bar1);
                instanceBar2 = (GameObject)Object.Instantiate(bar2);

                instanceBar1.transform.position = new Vector3(-4f, -4, 0);
                instanceBar2.transform.position = new Vector3(8, -4, 0);
            }

        }
        if (_modele_game_ref.tick == 0)
        {
            if (_modele_game_ref.manche == 0)
            {
                if (_modele_game_ref.howToPlaySt==0)
                {
                    GUI.skin = bt;
                    if (GUI.Button(new Rect((Screen.width / 2) - 235, 220, 210, 50), "Start Game") )
                    {
                        Object.Destroy(instanceMenu);
                        _venyl = new venyl(this);
                        _modele_game_ref.manche++;
                        _modele_game_ref.isPlaying = true;
                    }
                    if (_modele_game_ref.difficulty != 1)
                    {
                        GUI.skin = bt;
                        if (GUI.Button(new Rect((Screen.width / 2) - 235, 280, 210, 50), "Normal"))
                        {
                            _modele_game_ref.difficulty = 1;
                        }
                    }
                    else
                    {
                        GUI.skin = txt;
                        if (GUI.Button(new Rect((Screen.width / 2) - 235, 280, 210, 40), "Normal"))
                        {
                            _modele_game_ref.difficulty = 1;
                        }

                    }
                    if (_modele_game_ref.difficulty != 1.6f)
                    {
                        GUI.skin = bt;
                        if (GUI.Button(new Rect((Screen.width / 2) - 235, 320, 210, 40), "Hard"))
                        {
                            _modele_game_ref.difficulty = 1.6f;
                        }
                    }
                    else
                    {
                        GUI.skin = txt;
                        if (GUI.Button(new Rect((Screen.width / 2) - 235, 320, 210, 40), "Hard"))
                        {
                            _modele_game_ref.difficulty = 1.6f;
                        }
                    }
                    if (_modele_game_ref.difficulty != 2)
                    {
                        GUI.skin = bt;
                        if (GUI.Button(new Rect((Screen.width / 2) - 235, 360, 210, 40), "Expert"))
                        {
                            _modele_game_ref.difficulty = 2;
                        }
                    }
                    else
                    {
                        GUI.skin = txt;
                        if (GUI.Button(new Rect((Screen.width / 2) - 235, 360, 210, 40), "Expert"))
                        {
                            _modele_game_ref.difficulty = 2;
                        }
                    }
                    GUI.skin = bt;
                    if (GUI.Button(new Rect((Screen.width / 2) - 235, 410, 210, 50), "How to play"))
                    {
                        _modele_game_ref.howToPlaySt ++;
                        Object.Destroy(instanceMenu);
                        instanceMenu = (GameObject)Object.Instantiate(HowTo);
                    }
                    if (GUI.Button(new Rect((Screen.width / 2) - 235, 470, 210, 50), "Exit game"))
                    {
                        Application.Quit();
                    }
                }
                else
                {
                    if (GUI.Button(new Rect((Screen.width / 2) - 220, Screen.height - 103, 210, 50), "Back"))
                    {
                        if (_modele_game_ref.howToPlaySt == 1)
                        {
                            Object.Destroy(instanceMenu);
                            instanceMenu = (GameObject)Object.Instantiate(PochMenu);
                            _modele_game_ref.howToPlaySt--;
                        }
                        else
                        {
                            Object.Destroy(instanceMenu);
                            instanceMenu = (GameObject)Object.Instantiate(HowTo);
                            _modele_game_ref.howToPlaySt--;
                        }

                    }
                    if (GUI.Button(new Rect((Screen.width / 2) , Screen.height - 103, 210, 50), "Next"))
                    {
                        if (_modele_game_ref.howToPlaySt == 1)
                        {
                            Object.Destroy(instanceMenu);
                            instanceMenu = (GameObject)Object.Instantiate(HowTo2);
                            _modele_game_ref.howToPlaySt++;
                        }
                        else
                        {
                            Object.Destroy(instanceMenu);
                            instanceMenu = (GameObject)Object.Instantiate(PochMenu);
                            _modele_game_ref.howToPlaySt=0;
                        }
                    }
                }

            }
            else if (_modele_game_ref.manche % 2 == 0)
            {
                GUI.skin = txt;
                scObject dataP1 = _modele_game_ref.scoreData.getSCObject((_modele_game_ref.manche - 2));
                scObject dataP2 = new scObject(_modele_game_ref.manche.ToString());
                        if (_modele_game_ref.hit == 0)
                        {
                            _modele_game_ref.hit = 1;
                        }
                        dataP2.addInt("hit", _modele_game_ref.hit);
                        dataP2.addInt("succes", _modele_game_ref.success);
                        dataP2.addInt("score", _modele_game_ref.scoreP2);

                // afficher lorsque manche est paire???
                if ((((dataP2.getInt("succes") * 1f) / dataP2.getInt("hit")) * (dataP2.getInt("score"))) < ((dataP1.getInt("succes") * 1f) / dataP1.getInt("hit") * (dataP1.getInt("score"))))
                {
                    GUI.Label(new Rect((Screen.width - 200) / 2, 50, 200, 200), "Player 1 Win!!!!");
                }
                else if ((((dataP2.getInt("succes") * 1f) / dataP2.getInt("hit")) * (dataP2.getInt("score"))) == ((dataP1.getInt("succes") * 1f) / dataP1.getInt("hit") * (dataP1.getInt("score"))))
                {
                    GUI.Label(new Rect((Screen.width-200)/2, 50, 200, 200), "Tie!!!!");

                }
                else
                {
                    GUI.Label(new Rect((Screen.width - 200) / 2, 50, 200, 200), "Player 2 Win!!!!");

                }
                GUI.Label(new Rect(10, 10, 200, 50), "Player 1");

                GUI.Label(new Rect(155, 110, 200, 50),(dataP1.getInt("score")).ToString()+" Pts");

                GUI.Label(new Rect(160, 170, 200, 50), (Mathf.Round((dataP1.getInt("succes") * 1f) / dataP1.getInt("hit") * 100f)).ToString() + " l 100");
                instanceBar1.transform.localScale = new Vector3(2, ((dataP1.getInt("succes") * 1f) / dataP1.getInt("hit"))* 2, 1);

                //GUI.Label(new Rect(100, 200, 400, 200), "Normalised score: " + Mathf.Round(((dataP1.getInt("succes") * 1f) /dataP1.getInt("hit") * (dataP1.getInt("score")))).ToString() + "Pts");

                GUI.Label(new Rect(Screen.width-210, 10, 200, 50), "Player 2");
                GUI.Label(new Rect(Screen.width-400, 110, 200, 50), (dataP2.getInt("score")).ToString() + " Pts");

                GUI.Label(new Rect(Screen.width-360, 170, 200, 50), (Mathf.Round((dataP2.getInt("succes") * 1f) / dataP2.getInt("hit") * 100f)).ToString() + " l 100");
                instanceBar2.transform.localScale = new Vector3(2, ((dataP2.getInt("succes") * 1f) / dataP2.getInt("hit"))*2, 1);

                //GUI.Label(new Rect(600, 200, 400, 200), "Normalised score: " + Mathf.Round((((dataP2.getInt("succes") * 1f) / dataP2.getInt("hit")) * (dataP2.getInt("score")))).ToString() + "Pts");

                GUI.skin = bt;
                if (GUI.Button(new Rect(Screen.width - (Screen.width / 3 * 2), Screen.height - 50, Screen.width / 3, 50), "Start New Game"))
                {
                    Object.Destroy(instanceBar1);
                    Object.Destroy(instanceBar2);
                    Object.Destroy(instanceMeter);

                        scObject dataScore = new scObject(_modele_game_ref.manche.ToString());
                        dataScore.addInt("hit", _modele_game_ref.hit);
                        dataScore.addInt("succes", _modele_game_ref.success);
                        dataScore.addInt("score", _modele_game_ref.scoreP2);
                        _modele_game_ref.scoreData.addSCObject(dataScore);
                        _modele_game_ref.hit = 0;
                        _modele_game_ref.success = 0;
                        _modele_game_ref.scoreP1 = 0;
                        _modele_game_ref.multiplier = 1;
                        _modele_game_ref.streak = 0;
                        _modele_game_ref.manche++;
                        _modele_game_ref.offTick = 0;
                    _venyl = new venyl(this);
                    _modele_game_ref.isPlaying = true;
                   // t_timer.Start();
                }
                if (GUI.Button(new Rect(Screen.width - (Screen.width / 3), Screen.height - 50, Screen.width / 3, 50), "Exit Game"))
                {
                    Application.Quit();
                }
                if (GUI.Button(new Rect(Screen.width - (Screen.width / 3 * 3), Screen.height - 50, Screen.width / 3, 50), "Credit"))
                {
                    _modele_game_ref.credit = true;
                    instanceMenu = (GameObject)Object.Instantiate(Credit);
                }
                if (_modele_game_ref.credit)
                {
                    if (GUI.Button(new Rect(Screen.width - (Screen.width / 3 * 2), Screen.height - 100, Screen.width / 4, 50), "Close"))
                    {
                        _modele_game_ref.credit = false;
                        Object.Destroy(instanceMenu);
                    }
                }
            }
            else
            {

                if (GUI.Button(new Rect((Screen.width / 2) - 235,  250, 250, 50), "Switch Side"))
                {
                    Object.Destroy(instanceMenu);

                    scObject dataScore = new scObject(_modele_game_ref.manche.ToString());
                    if (_modele_game_ref.hit == 0)
                    {
                        _modele_game_ref.hit = 1;
                    }

                    dataScore.addInt("hit", _modele_game_ref.hit);
                    dataScore.addInt("succes", _modele_game_ref.success);
                    dataScore.addInt("score", _modele_game_ref.scoreP1);
                    _modele_game_ref.scoreData.addSCObject(dataScore);
                    _modele_game_ref.hit=0;
                    _modele_game_ref.success=0;
                    _modele_game_ref.scoreP1 = 0;
                    _modele_game_ref.multiplier = 1;
                    _modele_game_ref.streak = 0;
                    _modele_game_ref.tick = 1;

                    _modele_game_ref.manche++;
                    _venyl = new venyl(this);
                    _modele_game_ref.isPlaying = true;
                   /// t_timer.Start();
                }
            }
        }

        int hit = 1;
        if (_modele_game_ref.hit != 0)
        {
            hit = _modele_game_ref.hit;
        }
        if (_modele_game_ref.isPlaying)
        {
            //GUI.Label(new Rect(Screen.width-220, 40, 400, 200), "Raw Score:");
            //GUI.Label(new Rect(600, 75, 400, 200), "P2 Raw Score:");
            //GUI.Label(new Rect(Screen.width - 200, 125, 400, 200), "Notes Hit: ");
            //GUI.Label(new Rect(600, 125, 400, 200), "P1 Notes Hit: ");
            //GUI.Label(new Rect(Screen.width - 200, 175, 400, 200), "Final Score:");
           // GUI.Label(new Rect(600, 175, 400, 200), "P1 Final Score:");
            GUI.skin = txt;
            //GUI.Label(new Rect(600, 95, 400, 200), (scorePlayer2).ToString());
            if (_modele_game_ref.manche % 2 == 1)
            {
                GUI.Label(new Rect(Screen.width - 600*mod, 150*((Screen.height*1f)/Screen.width), 200, 50), (_modele_game_ref.scoreP1).ToString());
                if (_modele_game_ref.hit > 0)
                {
                    //GUI.Label(new Rect(Screen.width - 200, 145, 400, 200), Mathf.Round((_modele_game_ref.success * 1f) / _modele_game_ref.hit * 100f).ToString() + " %");
                    //GUI.Label(new Rect(Screen.width - 200, 195, 400, 200), Mathf.Round((((_modele_game_ref.success * 1f) / _modele_game_ref.hit) * (scorePlayer1))).ToString() + " points");
                }
            }
            else
            {
                GUI.Label(new Rect(Screen.width - 600 * mod, 150 * ((Screen.height * 1f) / Screen.width), 200, 50), (_modele_game_ref.scoreP2).ToString());
                //GUI.Label(new Rect(Screen.width - 200, 145, 400, 200), Mathf.Round((_modele_game_ref.successTemp * 1f) / _modele_game_ref.hitTemp * 100f).ToString() + " %");
                //GUI.Label(new Rect(Screen.width - 200, 195, 400, 200), Mathf.Round((((_modele_game_ref.successTemp * 1f) / _modele_game_ref.hitTemp) * (_modele_game_ref.scoreTemp))).ToString() + " points");
                /*if (_modele_game_ref.hit > 0)
                {
                    GUI.Label(new Rect(600, 145, 400, 200), Mathf.Round((_modele_game_ref.success * 1f) / _modele_game_ref.hit * 100f).ToString() + " %");
                    GUI.Label(new Rect(600, 195, 400, 200), Mathf.Round((((_modele_game_ref.success * 1f) / _modele_game_ref.hit) * (scorePlayer2))).ToString() + " points");
                }*/

            }
            /*GUI.Label(new Rect(500, 30, 400, 200), "Time:");
            GUI.Label(new Rect(500, 50, 400, 200), Mathf.Round((_modele_game_ref.tick / 10f)).ToString());*/
            _venyl.uiLoop();
        }
    }
    public void clipNotes(int tick)
    {
        barsSprites.Add(instanceBar);
            barsSprites[(barsSprites.Count) - 1].transform.parent = instance.transform;
            instanceBar = (GameObject)Object.Instantiate(bar);
            if (!_modele_venyl_ref.note1 && !_modele_venyl_ref.note2 && !_modele_venyl_ref.note3 && !_modele_venyl_ref.note4 && _modele_venyl_ref.typeAccordSvt > 0)
            {
                _controller_game_ref.incrementToken();
            }

        if (_modele_venyl_ref.note1)
        {
            notesSprites.Add(instance1);
            notesSprites[(notesSprites.Count) - 1].transform.parent = instance.transform;
            instance1 = new GameObject();

        }
        if (_modele_venyl_ref.note2)
        {
            notesSprites.Add(instance2);
            notesSprites[(notesSprites.Count) - 1].transform.parent = instance.transform;
            instance2 = new GameObject();

        }
        if (_modele_venyl_ref.note3)
        {
            notesSprites.Add(instance3);
            notesSprites[(notesSprites.Count) - 1].transform.parent = instance.transform;
            instance3 = new GameObject();
        }
        if (_modele_venyl_ref.note4)
        {
            notesSprites.Add(instance4);
            notesSprites[(notesSprites.Count) - 1].transform.parent = instance.transform;
            instance4 = new GameObject();
        }

            bool temp = false;
            switch (_modele_venyl_ref.typeAccordSvt)
            {
                case 1:
                        temp = _modele_venyl_ref.note1;
                        _modele_venyl_ref.note1=_modele_venyl_ref.note2;
                        _modele_venyl_ref.note2 = _modele_venyl_ref.note3;
                        _modele_venyl_ref.note3 = _modele_venyl_ref.note4;
                        _modele_venyl_ref.note4 = temp;
                    break;
                case 2:
                          temp = _modele_venyl_ref.note4;
                        _modele_venyl_ref.note4 = _modele_venyl_ref.note3;
                        _modele_venyl_ref.note3 = _modele_venyl_ref.note2;
                        _modele_venyl_ref.note2 = _modele_venyl_ref.note1;
                        _modele_venyl_ref.note1 = temp;
                    break;
                case 3:
                        temp = _modele_venyl_ref.note1;
                        _modele_venyl_ref.note1=_modele_venyl_ref.note4;
                        _modele_venyl_ref.note4=temp;

                        temp = _modele_venyl_ref.note2;
                        _modele_venyl_ref.note2=_modele_venyl_ref.note3;
                        _modele_venyl_ref.note3=temp;
                    break;

            }
            _modele_venyl_ref.typeAccordSvt=0;
        scObject note = new scObject("");

        if (_modele_venyl_ref.note1)
        {
            _modele_venyl_ref.note1 = false;
            _modele_venyl_ref.nbNotes--;
            note = new scObject("note1");
            note.addInt("time", tick);
            note.addInt("type", 1);
            note.addBool("deleted", false);
            _modele_venyl_ref.notes.addSCObject(note);
        }
        if (_modele_venyl_ref.note2)
        {
            _modele_venyl_ref.note2 = false;
            _modele_venyl_ref.nbNotes--;
            note = new scObject("note2");
            note.addInt("time", tick);
            note.addInt("type", 2);
            note.addBool("deleted", false);
            _modele_venyl_ref.notes.addSCObject(note);
        }
        if (_modele_venyl_ref.note3)
        {
            _modele_venyl_ref.note3 = false;
            _modele_venyl_ref.nbNotes--;
            note = new scObject("note3");
            note.addInt("time", tick);
            note.addInt("type", 3);
            note.addBool("deleted", false);
            _modele_venyl_ref.notes.addSCObject(note);
        }
        if (_modele_venyl_ref.note4)
        {
            _modele_venyl_ref.note4 = false;
            _modele_venyl_ref.nbNotes--;
            note = new scObject("note4");
            note.addInt("time", tick);
            note.addInt("type", 4);
            note.addBool("deleted", false);
            _modele_venyl_ref.notes.addSCObject(note);
        }
    }