Esempio n. 1
0
    void manageConnections(float deltaTime)
    {
        List <Call> callsToDelete = new List <Call> ();

        foreach (Call call in calls)
        {
            string connected     = sockControl.getConnectedTo(call.incomingPort);
            string tapConnection = sockControl.getConnectedTo("tappingSocket");
            bool   keepAlive     = call.handleState(connected, sockControl, OPERATOR_NAME, conversationHandler, strikeCounter);

            if (!keepAlive)
            {
                callsToDelete.Add(call);
            }
        }

        foreach (Call call in callsToDelete)
        {
            Debug.Log("Killing " + call.incomingPort);
            calls.Remove(call);
        }
        // !!!!!!!!!WARNING: HORRIBLE CODE BELOW!!!!!!!!!!!!

        //Ask andy code for connection complete for the pair
        //Once connection made

        //if tooperator
        //display connection pair request text
        //if this is the story, display the story text instead
        //else
//			//don't display call unless tapped
//		//Debug.Log("MANAGING()");
//		for (int i=0; i<calls.Count; i++) {
//			// Polling loop
//
//			//if(sockControl.getConnectedTo(calls[i].incomingPort)!=null)
//				//Debug.Log("ID:"+i+"PORT:"+calls[i].incomingPort+" connected to "+sockControl.getConnectedTo(calls[i].incomingPort).name+" Target:"+calls[i].targetPort);
//
//
//			if(!calls[i].spokenToOperator && sockControl.getConnectedTo(calls[i].incomingPort)!=null && sockControl.getConnectedTo(calls[i].incomingPort).name=="operator" && !inconversation)
//			{
//				//Debug.Log("CONNTECED CORRECTLY");
//				calls[i].spokenToOperator = true;
//				//get operator[story] conversation next & display
//				curconv = loader.getNextConversation();
//				curconv.setFormatter(sockControl.getSocket(calls[i].targetPort).getRandomName());
//				Debug.Log("targetPort::"+calls[i].targetPort);
//				StartCoroutine(sendConversation());
//				inconversation = true;
//				sockControl.setLED (calls[i].incomingPort, "GREEN");
//				sockControl.setLED ("operator", "GREEN");
//                opConnected = true;
//			}
//			else if(calls[i].spokenToOperator && sockControl.getConnectedTo(calls[i].incomingPort) != null && sockControl.getConnectedTo(calls[i].incomingPort).name==calls[i].targetPort)
//			{
//                //Debug.Log("CONNTECED CORRECTLY");
//                score++;
//				calls[i].connected = true;
//				sockControl.setLED (calls[i].incomingPort, "GREEN");
//				sockControl.setLED (calls[i].targetPort, "GREEN");
//			}
//			else if(calls[i].spokenToOperator && sockControl.getConnectedTo(calls[i].incomingPort) != null && (sockControl.getConnectedTo(calls[i].incomingPort).name!=calls[i].targetPort && sockControl.getConnectedTo(calls[i].incomingPort).name != "operator"))
//			{
//				//DROP CALL
//				sockControl.setLED (calls[i].incomingPort, "OFF");
//                sockControl.getSocket(calls[i].incomingPort).markedForUse = false;
//                sockControl.getSocket(calls[i].targetPort).markedForUse = false;
//                calls.RemoveAt(i);
//                Debug.Log("Dropped Call");
//			}
//			if(calls[i].connected)
//			{
//                Debug.Log("ID:" + i + " t:" + calls[i].timeLeft);
//				calls[i].timeLeft -= deltaTime;
//				if(calls[i].timeLeft < 0)
//				{
//					sockControl.setLED (calls[i].incomingPort, "OFF");
//					sockControl.setLED (calls[i].targetPort, "OFF");
//					calls.RemoveAt(i);
//				}
//                else
//                {
//                    if(sockControl.getConnectedTo(calls[i].incomingPort) == null)
//                    {
//                        sockControl.setLED(calls[i].incomingPort, "OFF");
//                        sockControl.setLED(calls[i].targetPort, "OFF");
//                        sockControl.getSocket(calls[i].incomingPort).markedForUse = false;
//                        sockControl.getSocket(calls[i].targetPort).markedForUse = false;
//                        calls.RemoveAt(i);
//                    }
//                }
//			}
//            if(opConnected && sockControl.getConnectedTo("operator") == null)
//            {
//                opConnected = false;
//                txtwrite.Say("[Disconnected]",new Color(),"left",true);
//            }
//		}

        //Display the LED for the incoming call
    }